Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2015 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  import copy 
  27  from numpy import array, asarray, average, exp, median, inf, isnan, linspace, log, std, sum, zeros 
  28  from minfx.generic import generic_minimise 
  29  from random import gauss 
  30  import re, math 
  31  from tempfile import mkdtemp, NamedTemporaryFile 
  32   
  33   
  34  # relax module imports. 
  35  from auto_analyses import relax_disp 
  36  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  37  from data_store import Relax_data_store; ds = Relax_data_store() 
  38  import dep_check 
  39  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_FULL, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  40  from lib.errors import RelaxError 
  41  from lib.io import extract_data, get_file_path 
  42  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  43  from pipe_control.mol_res_spin import generate_spin_string, return_spin, spin_loop 
  44  from pipe_control.minimise import assemble_scaling_matrix 
  45  from specific_analyses.relax_disp.checks import check_missing_r1 
  46  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  47  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  48  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  49  from specific_analyses.relax_disp.model import models_info, nesting_param 
  50  from specific_analyses.relax_disp.parameters import linear_constraints 
  51  from status import Status; status = Status() 
  52  from target_functions.relax_fit_wrapper import Relax_fit_opt 
  53  from test_suite.system_tests.base_classes import SystemTestCase 
  54   
  55   
56 -class Relax_disp(SystemTestCase):
57 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 58
59 - def __init__(self, methodName='runTest'):
60 """Skip certain tests if the C modules are non-functional. 61 62 @keyword methodName: The name of the test. 63 @type methodName: str 64 """ 65 66 # Execute the base class method. 67 super(Relax_disp, self).__init__(methodName) 68 69 # Tests to skip. 70 blacklist = [ 71 'test_m61b_data_to_m61b' 72 ] 73 if methodName in blacklist: 74 status.skipped_tests.append([methodName, None, self._skip_type]) 75 76 # Missing module. 77 if not dep_check.C_module_exp_fn: 78 # The list of tests to skip. 79 to_skip = [ 80 "test_bug_atul_srivastava", 81 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 82 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 83 "test_estimate_r2eff_err", 84 "test_estimate_r2eff_err_auto", 85 "test_estimate_r2eff_err_methods", 86 "test_finite_value", 87 "test_exp_fit", 88 "test_m61_exp_data_to_m61", 89 "test_r1rho_kjaergaard_auto", 90 "test_r1rho_kjaergaard_auto_check_graphs", 91 "test_r1rho_kjaergaard_man", 92 "test_r1rho_kjaergaard_missing_r1", 93 "test_value_write_calc_rotating_frame_params_auto_analysis" 94 ] 95 96 # Store in the status object. 97 if methodName in to_skip: 98 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 99 100 # If not scipy.optimize.leastsq. 101 if not dep_check.scipy_module: 102 # The list of tests to skip. 103 to_skip = [ 104 "test_estimate_r2eff_err_methods" 105 ] 106 107 # Store in the status object. 108 if methodName in to_skip: 109 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 110 111 # If not NMRPipe showApod program in PATH. 112 if not dep_check.showApod_software: 113 # The list of tests to skip. 114 to_skip = [ 115 "test_show_apod_extract", 116 "test_show_apod_rmsd", 117 "test_show_apod_rmsd_to_file", 118 "test_show_apod_rmsd_dir_to_files" 119 ] 120 121 # Store in the status object. 122 if methodName in to_skip: 123 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 124 125 # If not matplotlib module 126 if not dep_check.matplotlib_module: 127 # The list of tests to skip. 128 to_skip = [ 129 "test_repeat_cpmg" 130 ] 131 132 # Store in the status object. 133 if methodName in to_skip: 134 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
135 136
137 - def setUp(self):
138 """Set up for all the functional tests.""" 139 140 # Create the data pipe. 141 self.interpreter.pipe.create('relax_disp', 'relax_disp') 142 143 # Create a temporary directory for dumping files. 144 ds.tmpdir = mkdtemp() 145 self.tmpdir = ds.tmpdir
146 147
148 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
149 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 150 151 @keyword folder: The name of the folder for the test data. 152 @type folder: str 153 @keyword model_analyse: The name of the model which will be tested. 154 @type model_analyse: str 155 """ 156 157 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 158 159 # Data. 160 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 161 162 ## Experiments 163 # Exp 1 164 sfrq_1 = 500.0*1E6 165 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 166 time_T2_1 = 0.05 167 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 168 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 169 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 170 r2eff_errs_1 = [0.0] * len(ncycs_1) 171 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 172 173 sfrq_2 = 600.0*1E6 174 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 175 time_T2_2 = 0.06 176 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 177 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 178 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 179 r2eff_errs_2 = [0.0] * len(ncycs_2) 180 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 181 182 sfrq_3 = 700.0*1E6 183 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 184 time_T2_3 = 0.07 185 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 186 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 187 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 188 r2eff_errs_3 = [0.0] * len(ncycs_3) 189 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 190 191 # Collect all exps 192 exps = [exp_1, exp_2, exp_3] 193 194 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 195 dw_arr = [1.0, 2.0, 3.0, 4.0] 196 pA_arr = [0.9] 197 kex_arr = [1000.] 198 199 spins = [ 200 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 201 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 202 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 203 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 204 ] 205 206 # Create the data pipe. 207 pipe_name = 'base pipe' 208 pipe_type = 'relax_disp' 209 pipe_bundle = 'relax_disp' 210 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 211 212 # Generate the sequence. 213 for res_name, res_num, spin_name, params in spins: 214 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 215 216 # Set isotope 217 self.interpreter.spin.isotope('15N', spin_id='@N') 218 219 # Now loop over the experiments, to set the variables in relax. 220 exp_ids = [] 221 for exp_i in exps: 222 sfrq, time_T2, ncycs, r2eff_errs = exp_i 223 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 224 exp_ids.append(exp_id) 225 226 ids = [] 227 for ncyc in ncycs: 228 nu_cpmg = ncyc / time_T2 229 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 230 ids.append(cur_id) 231 232 # Set the spectrometer frequency. 233 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 234 235 # Set the experiment type. 236 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 237 238 # Set the relaxation dispersion CPMG constant time delay T (in s). 239 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 240 241 # Set the relaxation dispersion CPMG frequencies. 242 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 243 244 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 245 246 ### Now do fitting. 247 # Change pipe. 248 249 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 250 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 251 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 252 253 # Now read data in. 254 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 255 exp_id = exp_ids[mi] 256 exp_i = exps[mi] 257 sfrq, time_T2, ncycs, r2eff_errs = exp_i 258 259 # Then loop over the spins. 260 for res_name, res_num, spin_name, params in spins: 261 cur_spin_id = ":%i@%s"%(res_num, spin_name) 262 263 # Define file name 264 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 265 266 # Read in the R2eff file to put into spin structure. 267 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 268 269 # Then select model. 270 self.interpreter.relax_disp.select_model(model=model_analyse) 271 272 # Then cluster 273 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 274 275 # Grid search 276 low_arr = R20 + dw_arr + pA_arr + kex_arr 277 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 278 279 # Then loop over the defined spins and read the parameters. 280 for i in range(len(spins)): 281 res_name, res_num, spin_name, params = spins[i] 282 cur_spin_id = ":%i@%s"%(res_num, spin_name) 283 cur_spin = return_spin(cur_spin_id) 284 285 for mo_param in cur_spin.params: 286 print(mo_param) 287 # The R2 is a dictionary, depending on spectrometer frequency. 288 if isinstance(getattr(cur_spin, mo_param), dict): 289 for key, val in list(getattr(cur_spin, mo_param).items()): 290 should_be = params[mo_param][key] 291 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 292 self.assertAlmostEqual(val, should_be) 293 else: 294 should_be = float(params[mo_param]) 295 val = getattr(cur_spin, mo_param) 296 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 297 self.assertAlmostEqual(val, should_be) 298 299 # Test chi2. 300 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 301 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
302 303
304 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
305 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 306 307 # The path to the data files. 308 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 309 310 # Set pipe name, bundle and type. 311 ds.pipe_name = 'base pipe' 312 ds.pipe_bundle = 'relax_disp' 313 ds.pipe_type = 'relax_disp' 314 315 # Create the data pipe. 316 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 317 318 # Read the spins. 319 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 320 321 # Name the isotope for field strength scaling. 322 self.interpreter.spin.isotope(isotope='15N') 323 324 # Set number of experiments to be used. 325 NR_exp = 70 326 327 # Load the experiments settings file. 328 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 329 expfileslines = expfile.readlines()[:NR_exp] 330 expfile.close() 331 332 # In MHz 333 yOBS = 81.050 334 # In ppm 335 yCAR = 118.078 336 centerPPM_N15 = yCAR 337 338 ## Read the chemical shift data. 339 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 340 341 # The lock power to field, has been found in an calibration experiment. 342 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 343 344 # Apply spectra settings. 345 # Count settings 346 j = 0 347 for i in range(len(expfileslines)): 348 line = expfileslines[i] 349 if line[0] == "#": 350 continue 351 else: 352 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 353 DIRN = line.split()[0] 354 I = int(line.split()[1]) 355 deltadof2 = line.split()[2] 356 dpwr2slock = line.split()[3] 357 ncyc = int(line.split()[4]) 358 trim = float(line.split()[5]) 359 ss = int(line.split()[6]) 360 set_sfrq = float(line.split()[7]) 361 apod_rmsd = float(line.split()[8]) 362 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 363 364 # Calculate spin_lock time 365 time_sl = 2*ncyc*trim 366 367 # Define file name for peak list. 368 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 369 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 370 371 # Load the peak intensities. 372 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 373 374 # Set the peak intensity errors, as defined as the baseplane RMSD. 375 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 376 377 # Set the relaxation dispersion experiment type. 378 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 379 380 # Set The spin-lock field strength, nu1, in Hz 381 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 382 383 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 384 frq_N15_Hz = yOBS * 1E6 385 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 386 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 387 388 # Set The spin-lock offset, omega_rf, in ppm. 389 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 390 391 # Set the relaxation times (in s). 392 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 393 394 # Set the spectrometer frequency. 395 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 396 397 # Add to counter 398 j += 1 399 400 401 print("Testing the number of settings") 402 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 403 self.assertEqual(70, len(expfileslines)) 404 self.assertEqual(69, j) 405 self.assertEqual(69, len(cdp.exp_type)) 406 407 # Cluster spins 408 for curspin in cluster_ids: 409 print("Adding spin %s to cluster"%curspin) 410 self.interpreter.relax_disp.cluster('model_cluster', curspin) 411 412 # De-select for analysis those spins who have not been clustered 413 for free_spin in cdp.clustering['free spins']: 414 print("Deselecting free spin %s"%free_spin) 415 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 416 417 418 #Paper reference values 419 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 420 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 421 ds.ref = dict() 422 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 423 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 424 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 425 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 426 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 427 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 428 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 429 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 430 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 431 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 432 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 433 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 434 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 435 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 436 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 437 438 ds.guess = dict() 439 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 440 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 441 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 442 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 443 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 444 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 445 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 446 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 447 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 448 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 449 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 450 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 451 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 452 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 453 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 454 455 # Assign guess values. 456 for spin, spin_id in spin_loop(return_id=True): 457 if spin_id in cluster_ids: 458 print("spin_id %s in cluster ids"%(spin_id)) 459 spin.kex = ds.guess[spin_id][6] 460 spin.phi_ex = ds.guess[spin_id][10] 461 else: 462 print("spin_id %s NOT in cluster ids"%(spin_id)) 463 464 if read_R1: 465 # Read the R1 data 466 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
467 468
469 - def setup_hansen_cpmg_data(self, model=None):
470 """Set up the data for the test_hansen_cpmg_data_*() system tests. 471 472 @keyword model: The name of the model which will be tested. 473 @type model: str 474 """ 475 476 # Create the data pipe and load the base data. 477 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 478 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 479 self.interpreter.results.read(data_path+sep+'base_pipe') 480 self.interpreter.deselect.spin(':4') 481 482 # Set the nuclear isotope data. 483 self.interpreter.spin.isotope('15N') 484 485 # Create the R2eff data pipe and load the results. 486 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 487 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 488 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 489 self.interpreter.deselect.spin(':4') 490 491 # The model data pipe. 492 pipe_name = "%s - relax_disp" % model 493 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 494 self.interpreter.pipe.switch(pipe_name=pipe_name) 495 496 # Set the model. 497 self.interpreter.relax_disp.select_model(model=model) 498 499 # Copy the data. 500 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
501 502
503 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
504 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 505 506 @keyword model: The name of the model which will be tested. 507 @type model: str 508 """ 509 510 # Create the data pipe and load the base data. 511 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 512 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 513 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 514 515 # Create the R2eff data pipe and load the results. 516 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 517 self.interpreter.pipe.switch(pipe_name='R2eff') 518 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 519 520 # The model data pipe. 521 pipe_name = "%s - relax_disp" % model 522 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 523 self.interpreter.pipe.switch(pipe_name=pipe_name) 524 525 # Set the model. 526 self.interpreter.relax_disp.select_model(model=model) 527 528 # Copy the data. 529 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
530 531
532 - def setup_korzhnev_2005_data(self, data_list=[]):
533 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 534 535 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 536 537 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 538 539 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 540 541 542 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 543 @type data_list: list of str 544 """ 545 546 # Create the data pipe and load the base data. 547 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 548 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 549 550 # Create the spin system. 551 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 552 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 553 self.interpreter.spin.element('H', spin_id='@H') 554 self.interpreter.spin.element('N', spin_id='@N') 555 self.interpreter.spin.isotope('1H', spin_id='@H') 556 self.interpreter.spin.isotope('15N', spin_id='@N') 557 558 # Define the magnetic dipole-dipole relaxation interaction. 559 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 560 561 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 562 data = [ 563 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 564 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 565 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 566 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 567 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 568 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 569 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 570 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 571 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 572 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 573 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 574 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 575 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 576 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 577 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 578 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 579 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 580 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 581 ] 582 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 583 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 584 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 585 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 586 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 587 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 588 589 # Loop over the files, reading in the data. 590 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 591 # Skip undesired data. 592 if data_type not in data_list: 593 continue 594 595 # Alias the CPMG frequencies. 596 if data_type == 'SQ': 597 cpmg_frqs = cpmg_frqs_sq 598 elif data_type == '1H SQ': 599 cpmg_frqs = cpmg_frqs_1h_sq 600 elif data_type == 'DQ': 601 cpmg_frqs = cpmg_frqs_dq 602 elif data_type == 'ZQ': 603 cpmg_frqs = cpmg_frqs_zq 604 elif data_type == '1H MQ': 605 cpmg_frqs = cpmg_frqs_1h_mq 606 elif data_type == 'MQ': 607 cpmg_frqs = cpmg_frqs_mq 608 609 # Loop over each CPMG frequency. 610 for cpmg_frq in cpmg_frqs: 611 # The id. 612 new_id = "%s_%s" % (id, cpmg_frq) 613 614 # Set the NMR field strength. 615 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 616 617 # Set the relaxation dispersion experiment type. 618 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 619 620 # Relaxation dispersion CPMG constant time delay T (in s). 621 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 622 623 # Set the CPMG frequency. 624 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 625 626 # Read the R2eff data. 627 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 628 629 # Change the model. 630 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
631 632
633 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
634 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 635 636 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 637 'SOD1-WT' CPMG data to the CR72 dispersion model. 638 639 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 640 Data is for experiment at 25 degree Celcius. 641 """ 642 643 # Create the data pipe and load the base data. 644 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 645 646 # Set experiment settings. sfrq, time_T2, ncyc 647 Exps = [ 648 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 649 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 650 651 # Create base pipe 652 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 653 654 # Loop throug experiments 655 id_lists = [] 656 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 657 # Read spins 658 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 659 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 660 661 # Make spectrum id list 662 id_list = list(key+str(i) for i in range(len(ncycs))) 663 id_lists.append(id_list) 664 665 # Read intensities 666 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 667 668 # Loop over experiments 669 for i in range(len(ncycs)): 670 ncyc = ncycs[i] 671 vcpmg = ncyc/time_T2 672 673 # Test if spectrum is a reference 674 if float(vcpmg) == 0.0: 675 vcpmg = None 676 else: 677 vcpmg = round(float(vcpmg), 3) 678 679 # Set current id 680 current_id = id_list[i] 681 682 # Set the current experiment type. 683 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 684 685 # Set the NMR field strength of the spectrum. 686 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 687 688 # Relaxation dispersion CPMG constant time delay T (in s). 689 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 690 691 # Set the relaxation dispersion CPMG frequencies. 692 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 693 694 # Define replicated 695 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 696 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 697 698 # Perform error analysis 699 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 700 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 701 702 # Define isotope 703 self.interpreter.spin.isotope(isotope='15N') 704 705 ############# 706 707 # Define the 64 residues which was used for Global fitting 708 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 709 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 710 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 711 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 712 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 713 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 714 715 # Test number of global 716 self.assertEqual(64, len(glob_assn )) 717 718 ## Turn assignments into relax spin ids. 719 # Define regular expression search 720 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 721 722 # Create list to hold regular expression search 723 relax_glob_ids = [] 724 725 # Loop over assignments 726 for assn in glob_assn: 727 # Make match for the regular search 728 m = r.match(assn) 729 # Convert to relax spin string 730 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 731 732 # Save the relax spin string and the regular search 733 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 734 735 ############# Deselect all spins, and select few spins 736 737 ## Deselect all spins, and select a few for analysis 738 self.interpreter.deselect.all() 739 740 # Select few spins 741 for i in select_spin_index: 742 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 743 744 ############## 745 746 # Prepare for R2eff calculation 747 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 748 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 749 750 # Select model for points calculation 751 MODEL = "R2eff" 752 self.interpreter.relax_disp.select_model(model=MODEL) 753 # Calculate R2eff values 754 self.interpreter.minimise.calculate(verbosity=1)
755 756
757 - def setup_missing_r1_spins(self):
758 """Function for setting up a few spins for the given pipe.""" 759 760 # Path to file. 761 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 762 763 # File with spins. 764 file = open(data_path+sep+'R1_fitted_values.txt') 765 lines = file.readlines() 766 file.close() 767 768 for i, line in enumerate(lines): 769 # Make the string test 770 line_split = line.split() 771 772 if line_split[0] == "#": 773 continue 774 775 mol_name = line_split[0] 776 mol_name = None 777 res_num = int(line_split[1]) 778 res_name = line_split[2] 779 spin_num = line_split[3] 780 spin_num = None 781 spin_name = line_split[4] 782 783 # Create the spin. 784 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
785 786
787 - def setup_paul_schanda_nov_2015(self, outdir=None):
788 """This setup the truncated private data which was provided by Paul Schanda.""" 789 790 # Data path. 791 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Paul_Schanda_2015_Nov' 792 file = data_path + sep + '1_prepare_data.py' 793 794 # Store the out 795 status.outdir = outdir 796 797 # Run script. 798 self.interpreter.script(file=file, dir=None)
799 800
801 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
802 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 803 804 # Reset. 805 self.interpreter.reset() 806 807 # Create the data pipe and load the base data. 808 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 809 self.interpreter.state.load(data_path+sep+'r2eff_values') 810 811 # The model data pipe. 812 model = 'NS R1rho 2-site' 813 pipe_name = "%s - relax_disp" % model 814 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 815 self.interpreter.pipe.switch(pipe_name=pipe_name) 816 817 # Set the model. 818 self.interpreter.relax_disp.select_model(model=model) 819 820 # Copy the data. 821 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 822 823 # Alias the spins. 824 spin1 = cdp.mol[0].res[0].spin[0] 825 spin2 = cdp.mol[0].res[1].spin[0] 826 827 # The R20 keys. 828 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 829 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 830 831 # Set the initial parameter values. 832 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 833 spin1.pA = 0.779782428085762 834 spin1.dw = 7.57855284496424 835 spin1.kex = 1116.7911285203 836 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 837 spin2.pA = 0.826666229688602 838 spin2.dw = 9.5732624231366 839 spin2.kex = 1380.46162655657 840 841 # Test the values when clustering. 842 if clustering: 843 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 844 845 # Low precision optimisation. 846 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 847 848 # Printout. 849 print("\n\nOptimised parameters:\n") 850 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 851 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 852 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 853 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 854 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 855 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 856 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
857 858
859 - def test_baldwin_synthetic(self):
860 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 861 862 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 863 864 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 865 """ 866 867 # The path to the data files. 868 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 869 870 # Create pipe 871 pipe_name = 'base pipe' 872 pipe_type = 'relax_disp' 873 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 874 875 # Create base pipe 876 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 877 878 # Generate the sequence. 879 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 880 881 # Define the isotope. 882 self.interpreter.spin.isotope('1H', spin_id='@H') 883 884 # Build the experiment IDs. 885 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 886 ncycs = [2, 4, 8, 10, 20, 40, 500] 887 ids = [] 888 for ncyc in ncycs: 889 ids.append('CPMG_%s' % ncyc) 890 891 print("\n\nThe experiment IDs are %s." % ids) 892 893 # Set up the metadata for the experiments. 894 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 895 sfrq = 200. * 1E6 896 897 # Total time of CPMG block. 898 Trelax = 0.04 899 900 # First set the 901 for i in range(len(ids)): 902 id = ids[i] 903 # Set the spectrometer frequency. 904 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 905 906 # Set the experiment type. 907 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 908 909 # Set the relaxation dispersion CPMG constant time delay T (in s). 910 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 911 912 # Set the relaxation dispersion CPMG frequencies. 913 ncyc = ncycs[i] 914 nu_cpmg = ncyc / Trelax 915 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 916 917 # Prepare for R2eff reading. 918 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 919 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 920 921 # Try reading the R2eff file. 922 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 923 924 # Check the global data. 925 data = [ 926 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 927 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 928 ['dispersion_points', len(ncycs)], 929 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 930 ['exp_type_list', ['SQ CPMG']], 931 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 932 ['spectrometer_frq_count', 1], 933 ['spectrometer_frq_list', [sfrq]], 934 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 935 ] 936 for name, value in data: 937 # Does it exist? 938 self.assert_(hasattr(cdp, name)) 939 940 # Check the object. 941 obj = getattr(cdp, name) 942 if not isinstance(data, dict): 943 self.assertEqual(obj, value) 944 945 # Check the global dictionary data. 946 else: 947 for id in ids: 948 self.assertEqual(obj[id], value[id]) 949 950 # Check the spin data. 951 n_data = [ 952 [ 50.000000, 10.367900, 0.1], 953 [ 100.000000, 10.146849, 0.1], 954 [ 200.000000, 9.765987, 0.1], 955 [ 250.000000, 9.409789, 0.1], 956 [ 500.000000, 5.829819, 0.1], 957 [ 1000.000000, 3.191928, 0.1], 958 [ 12500.000000, 2.008231, 0.1] 959 ] 960 for disp_point, value, error in n_data: 961 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 962 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 963 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 964 965 # Generate r20 key. 966 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 967 968 ## Now prepare for MODEL calculation. 969 MODEL = "B14" 970 971 # Change pipe. 972 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 973 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 974 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 975 976 # Then select model. 977 self.interpreter.relax_disp.select_model(model=MODEL) 978 979 # Store grid and minimisations results. 980 grid_results = [] 981 mini_results = [] 982 983 # The grid search size (the number of increments per dimension). 984 # If None, use the default values. 985 #GRID = None 986 GRID = 13 987 # Perform Grid Search. 988 if GRID: 989 # Set the R20 parameters in the default grid search using the minimum R2eff value. 990 # This speeds it up considerably. 991 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 992 993 # Then do grid search. 994 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 995 996 # If no Grid search, set the default values. 997 else: 998 for param in MODEL_PARAMS[MODEL]: 999 self.interpreter.value.set(param=param, index=None) 1000 # Do a grid search, which will store the chi2 value. 1001 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1002 1003 # Store result. 1004 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1005 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1006 1007 ## Now do minimisation. 1008 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1009 set_func_tol = 1e-10 1010 set_max_iter = 1000 1011 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1012 1013 # Store result. 1014 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1015 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1016 1017 # Print results. 1018 for i in range(len(grid_results)): 1019 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1020 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1021 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1022 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1023 1024 # Reference values from Baldwin.py. 1025 # Exchange rate = k+ + k- (s-1) 1026 kex = 1000. 1027 # Fractional population of excited state k+/kex 1028 pb = 0.01 1029 # deltaOmega in ppm 1030 dw_ppm = 2. 1031 #relaxation rate of ground (s-1) 1032 R2g = 2. 1033 #relaxation rate of excited (s-1) 1034 R2e = 2. 1035 1036 # Test the parameters which created the data. 1037 # This is for the 1H spin. 1038 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1039 1040 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1041 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1042 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1043 1044
1046 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1047 1048 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1049 """ 1050 1051 # The path to the data files. 1052 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1053 1054 # Create pipe 1055 pipe_name = 'base pipe' 1056 pipe_type = 'relax_disp' 1057 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1058 1059 # Create base pipe 1060 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1061 1062 # Generate the sequence. 1063 # Generate both a 1H spin, and 15N spin. 1064 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1065 1066 # Define the isotope. 1067 self.interpreter.spin.isotope('1H', spin_id='@H') 1068 1069 # Build the experiment IDs. 1070 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1071 ncycs = [2, 4, 8, 10, 20, 40, 500] 1072 ids = [] 1073 for ncyc in ncycs: 1074 ids.append('CPMG_%s' % ncyc) 1075 1076 print("\n\nThe experiment IDs are %s." % ids) 1077 1078 # Set up the metadata for the experiments. 1079 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1080 sfrq = 200. * 1E6 1081 1082 # Total time of CPMG block. 1083 Trelax = 0.04 1084 1085 # First set the 1086 for i in range(len(ids)): 1087 id = ids[i] 1088 # Set the spectrometer frequency. 1089 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1090 1091 # Set the experiment type. 1092 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1093 1094 # Set the relaxation dispersion CPMG constant time delay T (in s). 1095 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1096 1097 # Set the relaxation dispersion CPMG frequencies. 1098 ncyc = ncycs[i] 1099 nu_cpmg = ncyc / Trelax 1100 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1101 1102 # Prepare for R2eff reading. 1103 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1104 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1105 1106 # Try reading the R2eff file. 1107 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1108 1109 # Check the global data. 1110 data = [ 1111 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1112 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1113 ['dispersion_points', len(ncycs)], 1114 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1115 ['exp_type_list', ['SQ CPMG']], 1116 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1117 ['spectrometer_frq_count', 1], 1118 ['spectrometer_frq_list', [sfrq]], 1119 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1120 ] 1121 for name, value in data: 1122 # Does it exist? 1123 self.assert_(hasattr(cdp, name)) 1124 1125 # Check the object. 1126 obj = getattr(cdp, name) 1127 if not isinstance(data, dict): 1128 self.assertEqual(obj, value) 1129 1130 # Check the global dictionary data. 1131 else: 1132 for id in ids: 1133 self.assertEqual(obj[id], value[id]) 1134 1135 # Check the spin data. 1136 n_data = [ 1137 [ 50.000000, 10.286255, 0.1], 1138 [ 100.000000, 10.073083, 0.1], 1139 [ 200.000000, 9.692746, 0.1], 1140 [ 250.000000, 9.382441, 0.1], 1141 [ 500.000000, 6.312396, 0.1], 1142 [ 1000.000000, 3.957029, 0.1], 1143 [ 12500.000000, 2.880420, 0.1] 1144 ] 1145 for disp_point, value, error in n_data: 1146 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1147 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1148 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1149 1150 # Generate r20 key. 1151 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1152 1153 ## Now prepare for MODEL calculation. 1154 MODEL = "B14 full" 1155 1156 # Change pipe. 1157 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1158 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1159 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1160 1161 # Then select model. 1162 self.interpreter.relax_disp.select_model(model=MODEL) 1163 1164 # Store grid and minimisations results. 1165 grid_results = [] 1166 mini_results = [] 1167 clust_results = [] 1168 1169 # The grid search size (the number of increments per dimension). 1170 # If None, use the default values. 1171 #GRID = None 1172 GRID = 13 1173 # Perform Grid Search. 1174 if GRID: 1175 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1176 # This speeds it up considerably. 1177 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1178 1179 # Then do grid search. 1180 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1181 1182 # If no Grid search, set the default values. 1183 else: 1184 for param in MODEL_PARAMS[MODEL]: 1185 self.interpreter.value.set(param=param, index=None) 1186 # Do a grid search, which will store the chi2 value. 1187 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1188 1189 # Store result. 1190 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1191 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1192 1193 ## Now do minimisation. 1194 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1195 set_func_tol = 1e-11 1196 set_max_iter = 10000 1197 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1198 1199 # Store result. 1200 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1201 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1202 1203 print("\n# Now print before and after minimisation-\n") 1204 1205 # Print results. 1206 for i in range(len(grid_results)): 1207 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1208 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1209 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1210 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1211 1212 # Reference values from Baldwin.py. 1213 # Exchange rate = k+ + k- (s-1) 1214 kex = 1000. 1215 # Fractional population of excited state k+/kex 1216 pb = 0.01 1217 # deltaOmega in ppm 1218 dw_ppm = 2. 1219 #relaxation rate of ground (s-1) 1220 R2g = 2. 1221 #relaxation rate of excited (s-1) 1222 R2e = 100. 1223 1224 # Test the parameters which created the data. 1225 # This is for the 1H spin. 1226 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1227 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1228 1229 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1230 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1231 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1232 1233
1234 - def x_test_bmrb_sub_cpmg(self):
1235 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1236 This uses CPMG data from: 1237 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1238 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1239 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1240 """ 1241 1242 # Define path to data 1243 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1244 1245 # Read data. 1246 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1247 1248 # Set element 1249 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1250 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1251 # Rename molecule from None to 'HEWL' 1252 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1253 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1254 1255 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1256 print(spin_id) 1257 if resn == 'C': 1258 print(resi, resn) 1259 1260 # Select the thiol state of the system. 1261 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1262 self.interpreter.bmrb.thiol_state(state='not reported') 1263 1264 # relax_data.temp_calibration(ri_id=None, method=None) 1265 1266 # Call display of bmrb. 1267 self.interpreter.bmrb.display()
1268 1269
1271 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1272 1273 # Clear the data store. 1274 self.interpreter.reset() 1275 1276 # Load the state. 1277 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1278 self.interpreter.state.load(state, force=True) 1279 1280 # Model selection - to catch the failure. 1281 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1282 1283
1285 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1286 1287 # Clear the data store. 1288 self.interpreter.reset() 1289 1290 # Load the state. 1291 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1292 self.interpreter.state.load(state, force=True) 1293 1294 # Execute the auto-analysis (fast). 1295 relax_disp.Relax_disp.opt_func_tol = 1e-5 1296 relax_disp.Relax_disp.opt_max_iterations = 1000 1297 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1298 1299
1301 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1302 1303 # Clear the data store. 1304 self.interpreter.reset() 1305 1306 # Load the state. 1307 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1308 self.interpreter.state.load(state, force=True) 1309 1310 # Execute the auto-analysis (fast). 1311 relax_disp.Relax_disp.opt_func_tol = 1e-5 1312 relax_disp.Relax_disp.opt_max_iterations = 1000 1313 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1314 1315
1317 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1318 1319 # Clear the data store. 1320 self.interpreter.reset() 1321 1322 # Load the state. 1323 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1324 self.interpreter.state.load(state, force=True) 1325 1326 # Run the calculation. 1327 self.interpreter.minimise.calculate(verbosity=1)
1328 1329
1331 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1332 1333 # Clear the data store. 1334 self.interpreter.reset() 1335 1336 # Load the state. 1337 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1338 self.interpreter.state.load(state, force=True) 1339 1340 # Execute the auto-analysis (fast). 1341 relax_disp.Relax_disp.opt_func_tol = 1e-5 1342 relax_disp.Relax_disp.opt_max_iterations = 1000 1343 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1344 1345
1347 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1348 1349 # Clear the data store. 1350 self.interpreter.reset() 1351 1352 # Load the state. 1353 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1354 self.interpreter.state.load(state, force=True) 1355 1356 # Execute the auto-analysis (fast). 1357 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1358 relax_disp.Relax_disp.opt_func_tol = 1e-5 1359 relax_disp.Relax_disp.opt_max_iterations = 1000 1360 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=3, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1361 1362
1364 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1365 1366 # Base data setup. 1367 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1368 1369
1371 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1372 1373 # Base data setup. 1374 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1375 1376
1378 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1379 1380 # Base data setup. 1381 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1382 1383
1385 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1386 1387 # Base data setup. 1388 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1389 1390
1392 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1393 1394 # Clear the data store. 1395 self.interpreter.reset() 1396 1397 # Load the state. 1398 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1399 self.interpreter.state.load(state, force=True) 1400 1401 param = 'k_AB' 1402 1403 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1404 print(spin_id, spin.params) 1405 if param in spin.params: 1406 print(spin_id, spin.k_AB, spin.k_AB_err) 1407 1408 # Perform write. 1409 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1410 1411 1412 # Test the header of the value.write parameter r2. 1413 param = 'r2' 1414 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1415 1416 file = open(self.tmpdir+sep+'%s.out'%param) 1417 lines = file.readlines() 1418 file.close() 1419 1420 for i, line in enumerate(lines): 1421 # Make the string test 1422 line_split = line.split() 1423 print(line_split) 1424 1425 if len(line_split) > 1: 1426 # Break at parameter header. 1427 if line_split[0] == "#" and line_split[1] == 'mol_name': 1428 nr_split_header = len(line_split) 1429 nr_split_header_i = i 1430 break 1431 1432 # Call the line after. 1433 line_split_val = lines[nr_split_header_i + 1].split() 1434 print(line_split_val) 1435 1436 # Assert that the number of columns is equal, plus 1 for "#". 1437 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1438 1439 # Test the header of the value.write for parameter r2eff. 1440 param = 'r2eff' 1441 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1442 1443 file = open(self.tmpdir+sep+'%s.out'%param) 1444 lines = file.readlines() 1445 file.close() 1446 1447 for i, line in enumerate(lines): 1448 # Make the string test 1449 line_split = line.split() 1450 print(line_split) 1451 1452 if len(line_split) > 1: 1453 # Break at parameter header. 1454 if line_split[0] == "#" and line_split[1] == 'mol_name': 1455 nr_split_header = len(line_split) 1456 nr_split_header_i = i 1457 break 1458 1459 # Call the line after. 1460 line_split_val = lines[nr_split_header_i + 1].split() 1461 print(line_split_val) 1462 1463 # Assert that the number of columns is equal, plus 1 for "#". 1464 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1465 1466
1468 """Catch U{bug #23186<https://gna.org/bugs/?23186>}: Error calculation of individual parameter "dw" from Monte-Carlo, is based on first spin.""" 1469 1470 # Clear the data store. 1471 self.interpreter.reset() 1472 1473 # Load the state. 1474 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_23186.bz2' 1475 self.interpreter.state.load(state, force=True) 1476 1477 # Dic key to spectrometer frq. 1478 dickey = 'SQ CPMG - 599.89086220 MHz' 1479 1480 # First get the resi 0 array of sim r2a. 1481 resi_0_r2a = [] 1482 1483 # Assign spins 1484 res0 = cdp.mol[0].res[0].spin[0] 1485 res1 = cdp.mol[0].res[1].spin[0] 1486 1487 print("Chi2 before call to minimise: %3.3f"%res0.chi2) 1488 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000, verbosity=0) 1489 print("Chi2 after call to minimise: %3.3f"%res0.chi2) 1490 1491 # Loop over the dics in spin. 1492 for cdic in res0.r2a_sim: 1493 resi_0_r2a.append(cdic[dickey]) 1494 1495 # Get stats with numpy 1496 resi_0_r2a_std = std(asarray(resi_0_r2a), ddof=1) 1497 1498 # First get the resi 86 array of sim r2a. 1499 resi_86_r2a = [] 1500 1501 # Loop over the dics in spin. 1502 for cdic in res1.r2a_sim: 1503 resi_86_r2a.append(cdic[dickey]) 1504 1505 # Get stats with numpy 1506 resi_86_r2a_std = std(asarray(resi_86_r2a), ddof=1) 1507 1508 # Then get for dw. 1509 1510 # First get the array of sim dw. 1511 resi_0_dw = res0.dw_sim 1512 resi_86_dw = res1.dw_sim 1513 1514 # Get stats with numpy 1515 resi_0_dw_std = std(asarray(resi_0_dw), ddof=1) 1516 resi_86_dw_std = std(asarray(resi_86_dw), ddof=1) 1517 1518 # Then get for spin independent parameter. 1519 1520 # First get the array of sim dw. 1521 resi_0_kAB = res0.k_AB_sim 1522 resi_86_kAB = res1.k_AB_sim 1523 1524 # Get stats with numpy 1525 resi_0_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1526 resi_86_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1527 1528 # Assume they both std of k_AB values are equal 1529 self.assertEqual(resi_0_kAB_std, resi_86_kAB_std) 1530 1531 # Perform error analysis. 1532 self.interpreter.monte_carlo.error_analysis() 1533 1534 # Check values for k_AB. 1535 self.assertAlmostEqual(resi_0_kAB_std, res0.k_AB_err) 1536 self.assertAlmostEqual(resi_86_kAB_std, res1.k_AB_err) 1537 1538 # Check values for r2a. 1539 self.assertAlmostEqual(resi_0_r2a_std, res0.r2a_err[dickey]) 1540 self.assertAlmostEqual(resi_86_r2a_std, res1.r2a_err[dickey]) 1541 1542 # Check values for dw. 1543 self.assertAlmostEqual(resi_0_dw_std, res0.dw_err) 1544 self.assertAlmostEqual(resi_86_dw_std, res1.dw_err) 1545 1546 # The following is for Bug #23619: (https://gna.org/bugs/index.php?23619): Stored chi2 sim values from Monte-Carlo simulations does not equal normal chi2 values. 1547 # This is to show that this bug is invalid. The "very" different chi2 values stems from r2eff points being back-calculated values rather than original measured values. 1548 1549 # Check calculates the same Monte-Carlo chi2 values 1550 self.interpreter.monte_carlo.setup(number=3) 1551 self.interpreter.monte_carlo.create_data(method='back_calc') 1552 self.interpreter.monte_carlo.initial_values() 1553 1554 # Assign original data instead of back_calculated error. 1555 res0.r2eff_sim[0] = copy.copy(res0.r2eff) 1556 res0.r2eff_sim[1] = copy.copy(res0.r2eff) 1557 res0.r2eff_sim[2] = copy.copy(res0.r2eff) 1558 res1.r2eff_sim[0] = copy.copy(res1.r2eff) 1559 res1.r2eff_sim[1] = copy.copy(res1.r2eff) 1560 res1.r2eff_sim[2] = copy.copy(res1.r2eff) 1561 1562 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000) 1563 self.interpreter.monte_carlo.error_analysis() 1564 1565 # Get the simulation array and calculate the average 1566 spin_chi2_mc = res0.chi2 1567 spin_chi2_mc_sim = res0.chi2_sim 1568 spin_chi2_mc_sim_ave = average(spin_chi2_mc_sim) 1569 1570 print("The chi2 from calculation is: %3.3f"%spin_chi2_mc) 1571 print("The array with monte-carlo chi2 values is: %s"%spin_chi2_mc_sim) 1572 print("The average of this array is: %3.3f"%spin_chi2_mc_sim_ave) 1573 1574 self.assertAlmostEqual(spin_chi2_mc, spin_chi2_mc_sim_ave, 7)
1575 1576
1578 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1579 1580 # Define path to data 1581 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1582 1583 # Read data. 1584 self.interpreter.results.read(prev_data_path + sep + 'results') 1585 1586 # Now count number 1587 graph_nr = 1 1588 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1589 print("\nGraph nr %i" % graph_nr) 1590 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1591 print(exp_type, frq, offset, point, time) 1592 graph_nr += 1 1593 1594 ## Possibly do an error analysis. 1595 1596 # Check if intensity errors have already been calculated by the user. 1597 precalc = True 1598 for spin in spin_loop(skip_desel=True): 1599 # No structure. 1600 if not hasattr(spin, 'peak_intensity_err'): 1601 precalc = False 1602 break 1603 1604 # Determine if a spectrum ID is missing from the list. 1605 for id in cdp.spectrum_ids: 1606 if id not in spin.peak_intensity_err: 1607 precalc = False 1608 break 1609 1610 # Skip. 1611 if precalc: 1612 print("Skipping the error analysis as it has already been performed.") 1613 1614 else: 1615 # Loop over the spectrometer frequencies. 1616 for frq in loop_frq(): 1617 # Generate a list of spectrum IDs matching the frequency. 1618 ids = [] 1619 for id in cdp.spectrum_ids: 1620 # Check that the spectrometer frequency matches. 1621 match_frq = True 1622 if frq != None and cdp.spectrometer_frq[id] != frq: 1623 match_frq = False 1624 1625 # Add the ID. 1626 if match_frq: 1627 ids.append(id) 1628 1629 # Run the error analysis on the subset. 1630 self.interpreter.spectrum.error_analysis(subset=ids) 1631 1632 print("has_exponential_exp_type:", has_exponential_exp_type()) 1633 1634 model = 'R2eff' 1635 self.interpreter.relax_disp.select_model(model) 1636 1637 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1638 #delattr(spin, 'r2eff') 1639 #delattr(spin, 'r2eff_err') 1640 #delattr(spin, 'i0') 1641 #delattr(spin, 'i0_err') 1642 setattr(spin, 'r2eff', {}) 1643 setattr(spin, 'r2eff_err', {}) 1644 setattr(spin, 'i0', {}) 1645 setattr(spin, 'i0_err', {}) 1646 1647 # Do Grid Search 1648 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1649 1650 # Start dic. 1651 my_dic = {} 1652 1653 # Define counter for maximum elements in the numpy array list 1654 NE = 0 1655 NS = 1 1656 NM = 0 1657 NO = 0 1658 ND = 0 1659 NT = 0 1660 1661 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1662 # Save to counter. 1663 if ei > NE: 1664 NE = ei 1665 if mi > NM: 1666 NM = mi 1667 if oi > NO: 1668 NO = oi 1669 if di > ND: 1670 ND = di 1671 1672 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1673 # Save to counter. 1674 if ti > NT: 1675 NT = ti 1676 1677 # Add 1 to counter, since index start from 0. 1678 NE = NE + 1 1679 NM = NM + 1 1680 NO = NO + 1 1681 ND = ND + 1 1682 NT = NT + 1 1683 1684 # Make data array. 1685 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1686 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1687 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1688 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1689 param_key_list = [] 1690 1691 1692 # Loop over each spectrometer frequency and dispersion point. 1693 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1694 # Add key to dic. 1695 my_dic[spin_id] = {} 1696 1697 # Generate spin string. 1698 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1699 1700 # Loop over the parameters. 1701 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1702 1703 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1704 # Generate the param_key. 1705 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1706 1707 # Append key. 1708 param_key_list.append(param_key) 1709 1710 # Add key to dic. 1711 my_dic[spin_id][param_key] = {} 1712 1713 # Get the value. 1714 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1715 i0_value = getattr(cur_spin, 'i0')[param_key] 1716 1717 # Save to dic. 1718 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1719 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1720 1721 ## Now try do a line of best fit by least squares. 1722 # The peak intensities, errors and times. 1723 values = [] 1724 errors = [] 1725 times = [] 1726 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1727 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1728 values.append(value) 1729 1730 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1731 errors.append(error) 1732 times.append(time) 1733 1734 # Save to numpy arrays. 1735 values_arr[ei, 0, mi, oi, di, ti] = value 1736 errors_arr[ei, 0, mi, oi, di, ti] = error 1737 times_arr[ei, 0, mi, oi, di, ti] = time 1738 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1739 1740 # y= A exp(x * k) 1741 # w[i] = ln(y[i]) 1742 # int[i] = i0 * exp( - times[i] * r2eff); 1743 w = log(array(values)) 1744 x = - array(times) 1745 n = len(times) 1746 1747 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1748 a = 1./n * sum(w) - b * 1./n * sum(x) 1749 R2eff_est = b 1750 i0_est = exp(a) 1751 1752 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1753 my_dic[spin_id][param_key]['i0_est'] = i0_est 1754 1755 # Print value. 1756 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1757 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1758 1759 1760 # Do minimisation. 1761 set_func_tol = 1e-25 1762 set_max_iter = int(1e7) 1763 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1764 1765 # Loop over each spectrometer frequency and dispersion point. 1766 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1767 # Generate spin string. 1768 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1769 1770 # Loop over the parameters. 1771 print("Optimised parameters for spin: %s" % (spin_string)) 1772 1773 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1774 # Generate the param_key. 1775 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1776 1777 # Get the value. 1778 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1779 i0_value = getattr(cur_spin, 'i0')[param_key] 1780 1781 # Extract from dic. 1782 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1783 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1784 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1785 i0_est = my_dic[spin_id][param_key]['i0_est'] 1786 1787 # Print value. 1788 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1789 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1790 1791 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1792 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1793 1794 print(NE, NS, NM, NO, ND, NT) 1795 for param_key in param_key_list: 1796 print(" '%s'," % param_key) 1797 print(values_arr.shape) 1798 1799 # Save arrays to profiling. 1800 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1801 #save(data_path + "values_arr", values_arr) 1802 #save(data_path + "errors_arr", errors_arr) 1803 #save(data_path + "times_arr", times_arr) 1804 #save(data_path + "struct_arr", struct_arr) 1805 1806
1807 - def test_bug_atul_srivastava(self):
1808 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1809 shows it is exponential fitting, but only one time point is added per file. 1810 1811 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1812 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1813 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1814 1815 """ 1816 1817 # Data path. 1818 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1819 file = data_path + sep + 'bug_script.py' 1820 1821 # Run script. 1822 self.interpreter.script(file=file, dir=None) 1823 1824 # The grid search size (the number of increments per dimension). 1825 GRID_INC = 11 1826 1827 # Check-data. 1828 ################# 1829 1830 # Loop over spins, to see current setup. 1831 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1832 print(mol_name, resi, resn, spin_id) 1833 1834 # Loop over setup. 1835 for id in cdp.exp_type: 1836 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1837 1838 1839 # Manual minimisation. 1840 ################# 1841 if True: 1842 # Set the model. 1843 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1844 1845 # Check if intensity errors have already been calculated. 1846 check_intensity_errors() 1847 1848 # Calculate the R2eff values for the fixed relaxation time period data types. 1849 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1850 self.interpreter.minimise.calculate() 1851 1852 # Optimise the model. 1853 else: 1854 constraints = False 1855 min_algor = 'Newton' 1856 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1857 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1858 1859 # Inspect. 1860 if False: 1861 # Loop over attributes. 1862 par_attr_list = ['r2eff', 'i0'] 1863 1864 # Collect the estimation data. 1865 my_dic = {} 1866 param_key_list = [] 1867 est_keys = [] 1868 est_key = 'grid' 1869 est_keys.append(est_key) 1870 spin_id_list = [] 1871 1872 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1873 # Add key to dic. 1874 my_dic[spin_id] = {} 1875 1876 # Add key for estimate. 1877 my_dic[spin_id][est_key] = {} 1878 1879 # Add spin key to list. 1880 spin_id_list.append(spin_id) 1881 1882 # Generate spin string. 1883 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1884 1885 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1886 # Generate the param_key. 1887 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1888 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1889 1890 # Append key. 1891 param_key_list.append(param_key) 1892 1893 # Add key to dic. 1894 my_dic[spin_id][est_key][param_key] = {} 1895 1896 # Get the value. 1897 # Loop over err attributes. 1898 for par_attr in par_attr_list: 1899 if hasattr(cur_spin, par_attr): 1900 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1901 else: 1902 get_par_attr = 0.0 1903 1904 # Save to dic. 1905 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1906 1907 # Check number of values. 1908 values = [] 1909 errors = [] 1910 times = [] 1911 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1912 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1913 values.append(value) 1914 1915 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1916 errors.append(error) 1917 times.append(time) 1918 1919 # Save to dic. 1920 my_dic[spin_id][est_key][param_key]['values'] = values 1921 my_dic[spin_id][est_key][param_key]['errors'] = errors 1922 my_dic[spin_id][est_key][param_key]['times'] = times 1923 1924 # Analysis variables. 1925 ##################### 1926 1927 # The dispersion models. 1928 MODELS = ['R2eff', 'No Rex'] 1929 1930 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1931 MC_NUM = 10 1932 1933 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1934 MC_SIM_ALL_MODELS = False 1935 1936 # The results directory. 1937 RESULTS_DIR = ds.tmpdir 1938 1939 # The directory of results of an earlier analysis without clustering. 1940 PRE_RUN_DIR = None 1941 1942 # The model selection technique to use. 1943 MODSEL = 'AIC' 1944 1945 # The flag for only using numeric models in the final model selection. 1946 NUMERIC_ONLY = False 1947 1948 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1949 INSIGNIFICANCE = 1.0 1950 1951 # Auto-analysis execution. 1952 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1953 1954
1956 """Test data, where peak intensities are negative in CPMG 1957 1958 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1959 """ 1960 1961 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1962 1963 # Create the spins 1964 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1965 1966 # Name the isotope for field strength scaling. 1967 self.interpreter.spin.isotope(isotope='15N') 1968 1969 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1970 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1971 1972 # Loop over the spectra settings. 1973 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1974 1975 # Make empty ncyclist 1976 ncyclist = [] 1977 1978 i = 0 1979 for line in ncycfile: 1980 ncyc = line.split()[0] 1981 time_T2 = float(line.split()[1]) 1982 vcpmg = line.split()[2] 1983 set_sfrq = float(line.split()[3]) 1984 rmsd_err = float(line.split()[4]) 1985 1986 # Test if spectrum is a reference 1987 if float(vcpmg) == 0.0: 1988 vcpmg = None 1989 else: 1990 vcpmg = round(float(vcpmg), 3) 1991 1992 # Add ncyc to list 1993 ncyclist.append(int(ncyc)) 1994 1995 # Set the current spectrum id 1996 current_id = "Z_A%s"%(i) 1997 1998 # Set the current experiment type. 1999 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 2000 2001 # Set the peak intensity errors, as defined as the baseplane RMSD. 2002 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 2003 2004 # Set the NMR field strength of the spectrum. 2005 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 2006 2007 # Relaxation dispersion CPMG constant time delay T (in s). 2008 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 2009 2010 # Set the relaxation dispersion CPMG frequencies. 2011 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 2012 2013 i += 1 2014 2015 # Specify the duplicated spectra. 2016 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 2017 2018 # Delete replicate spectrum 2019 #self.interpreter.spectrum.delete('Z_A15') 2020 2021 MODELS = [MODEL_R2EFF, MODEL_NOREX] 2022 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 2023 2024 results_dir = ds.tmpdir 2025 2026 # Execute 2027 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 2028 2029 # Check spin less R2eff points. 2030 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 2031 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 2032 if spin_id == ':4@N': 2033 self.assertEqual(len(cur_spin.r2eff), 14) 2034 else: 2035 self.assertEqual(len(cur_spin.r2eff), 15)
2036 2037
2038 - def test_check_missing_r1(self):
2039 """Test of the check_missing_r1() function.""" 2040 2041 # Set up some spins. 2042 self.setup_missing_r1_spins() 2043 2044 # Set variables. 2045 exp_type = 'R1rho' 2046 frq = 800.1 * 1E6 2047 2048 spectrum_id='test' 2049 2050 # Set an experiment type to the pipe. 2051 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 2052 2053 # Set a frequency to loop through. 2054 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 2055 2056 # Check R1 for DPL94. 2057 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2058 self.assertEqual(check_missing_r1_return, True) 2059 2060 # Check R1 for R2eff. 2061 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 2062 self.assertEqual(check_missing_r1_return, False) 2063 2064 # The path to the data files. 2065 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 2066 2067 # Now load some R1 data. 2068 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 2069 2070 # Check R1. 2071 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2072 self.assertEqual(check_missing_r1_return, False)
2073 2074
2076 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 2077 2078 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2079 2080 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2081 """ 2082 2083 # Reset. 2084 #self.interpreter.reset() 2085 2086 ## Set Experiments. 2087 model_create = 'B14' 2088 #model_create = 'NS CPMG 2-site expanded' 2089 model_analyse = 'NS CPMG 2-site 3D' 2090 2091 # Exp 1 2092 sfrq_1 = 599.8908617*1E6 2093 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2094 time_T2_1 = 0.06 2095 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2096 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2097 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2098 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2099 2100 sfrq_2 = 499.8908617*1E6 2101 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2102 time_T2_2 = 0.05 2103 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2104 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2105 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2106 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2107 2108 # Collect all exps 2109 exps = [exp_1, exp_2] 2110 2111 spins = [ 2112 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2113 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2114 ] 2115 2116 # Collect the data to be used. 2117 ds.data = [model_create, model_analyse, spins, exps] 2118 2119 # The tmp directory. None is the local directory. 2120 ds.tmpdir = ds.tmpdir 2121 2122 # The results directory. None is the local directory. 2123 #ds.resdir = None 2124 ds.resdir = ds.tmpdir 2125 2126 # Do r20_from_min_r2eff ?. 2127 ds.r20_from_min_r2eff = True 2128 2129 # Remove insignificant level. 2130 ds.insignificance = 0.0 2131 2132 # The grid search size (the number of increments per dimension). 2133 ds.GRID_INC = None 2134 2135 # The do clustering. 2136 ds.do_cluster = True 2137 2138 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2139 # The default value is 1e-25. 2140 ds.set_func_tol = 1e-1 2141 2142 # The maximum number of iterations. 2143 # The default value is 1e7. 2144 ds.set_max_iter = 1000 2145 2146 # The verbosity level. 2147 ds.verbosity = 1 2148 2149 # The rel_change WARNING level. 2150 ds.rel_change = 0.05 2151 2152 # The plot_curves. 2153 ds.plot_curves = False 2154 2155 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2156 ds.sherekhan_input = False 2157 2158 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2159 ds.opendx = False 2160 2161 # The set r2eff err. 2162 ds.r2eff_err = 0.1 2163 2164 # The print result info. 2165 ds.print_res = True 2166 2167 # Execute the script. 2168 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2169 2170 cur_spins = ds.data[2] 2171 # Compare results. 2172 for i in range(len(cur_spins)): 2173 res_name, res_num, spin_name, params = cur_spins[i] 2174 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2175 cur_spin = return_spin(cur_spin_id) 2176 2177 grid_params = ds.grid_results[i][3] 2178 2179 # Extract the clust results. 2180 min_params = ds.clust_results[i][3] 2181 # Now read the parameters. 2182 print("For spin: '%s'"%cur_spin_id) 2183 for mo_param in cur_spin.params: 2184 # The R2 is a dictionary, depending on spectrometer frequency. 2185 if isinstance(getattr(cur_spin, mo_param), dict): 2186 grid_r2 = grid_params[mo_param] 2187 min_r2 = min_params[mo_param] 2188 set_r2 = params[mo_param] 2189 for key, val in list(set_r2.items()): 2190 grid_r2_frq = grid_r2[key] 2191 min_r2_frq = min_r2[key] 2192 set_r2_frq = set_r2[key] 2193 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2194 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2195 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2196 if rel_change > ds.rel_change: 2197 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2198 print("###################################") 2199 2200 ## Make test on R2. 2201 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2202 else: 2203 grid_val = grid_params[mo_param] 2204 min_val = min_params[mo_param] 2205 set_val = params[mo_param] 2206 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2207 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2208 if rel_change > ds.rel_change: 2209 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2210 print("###################################") 2211 2212 ## Make test on parameters. 2213 if mo_param == 'dw': 2214 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2215 elif mo_param == 'kex': 2216 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2217 elif mo_param == 'pA': 2218 self.assertAlmostEqual(set_val, min_val, 2)
2219 2220
2222 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2223 2224 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2225 2226 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2227 """ 2228 2229 # Reset. 2230 #self.interpreter.reset() 2231 2232 ## Set Experiments. 2233 model_create = 'B14' 2234 #model_create = 'NS CPMG 2-site expanded' 2235 model_analyse = 'NS CPMG 2-site star' 2236 2237 # Exp 1 2238 sfrq_1 = 599.8908617*1E6 2239 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2240 time_T2_1 = 0.06 2241 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2242 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2243 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2244 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2245 2246 sfrq_2 = 499.8908617*1E6 2247 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2248 time_T2_2 = 0.05 2249 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2250 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2251 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2252 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2253 2254 # Collect all exps 2255 exps = [exp_1, exp_2] 2256 2257 spins = [ 2258 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2259 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2260 ] 2261 2262 # Collect the data to be used. 2263 ds.data = [model_create, model_analyse, spins, exps] 2264 2265 # The tmp directory. None is the local directory. 2266 ds.tmpdir = ds.tmpdir 2267 2268 # The results directory. None is the local directory. 2269 #ds.resdir = None 2270 ds.resdir = ds.tmpdir 2271 2272 # Do r20_from_min_r2eff ?. 2273 ds.r20_from_min_r2eff = True 2274 2275 # Remove insignificant level. 2276 ds.insignificance = 0.0 2277 2278 # The grid search size (the number of increments per dimension). 2279 ds.GRID_INC = None 2280 2281 # The do clustering. 2282 ds.do_cluster = True 2283 2284 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2285 # The default value is 1e-25. 2286 ds.set_func_tol = 1e-1 2287 2288 # The maximum number of iterations. 2289 # The default value is 1e7. 2290 ds.set_max_iter = 1000 2291 2292 # The verbosity level. 2293 ds.verbosity = 1 2294 2295 # The rel_change WARNING level. 2296 ds.rel_change = 0.05 2297 2298 # The plot_curves. 2299 ds.plot_curves = False 2300 2301 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2302 ds.sherekhan_input = False 2303 2304 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2305 ds.opendx = False 2306 2307 # The set r2eff err. 2308 ds.r2eff_err = 0.1 2309 2310 # The print result info. 2311 ds.print_res = True 2312 2313 # Execute the script. 2314 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2315 2316 cur_spins = ds.data[2] 2317 # Compare results. 2318 for i in range(len(cur_spins)): 2319 res_name, res_num, spin_name, params = cur_spins[i] 2320 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2321 cur_spin = return_spin(cur_spin_id) 2322 2323 grid_params = ds.grid_results[i][3] 2324 2325 # Extract the clust results. 2326 min_params = ds.clust_results[i][3] 2327 # Now read the parameters. 2328 print("For spin: '%s'"%cur_spin_id) 2329 for mo_param in cur_spin.params: 2330 # The R2 is a dictionary, depending on spectrometer frequency. 2331 if isinstance(getattr(cur_spin, mo_param), dict): 2332 grid_r2 = grid_params[mo_param] 2333 min_r2 = min_params[mo_param] 2334 set_r2 = params[mo_param] 2335 for key, val in list(set_r2.items()): 2336 grid_r2_frq = grid_r2[key] 2337 min_r2_frq = min_r2[key] 2338 set_r2_frq = set_r2[key] 2339 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2340 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2341 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2342 if rel_change > ds.rel_change: 2343 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2344 print("###################################") 2345 2346 ## Make test on R2. 2347 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2348 else: 2349 grid_val = grid_params[mo_param] 2350 min_val = min_params[mo_param] 2351 set_val = params[mo_param] 2352 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2353 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2354 if rel_change > ds.rel_change: 2355 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2356 print("###################################") 2357 2358 ## Make test on parameters. 2359 if mo_param == 'dw': 2360 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2361 elif mo_param == 'kex': 2362 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2363 elif mo_param == 'pA': 2364 self.assertAlmostEqual(set_val, min_val, 2)
2365 2366
2368 """Test synthetic cpmg data. 2369 2370 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2371 """ 2372 2373 # Reset. 2374 #self.interpreter.reset() 2375 2376 ## Set Experiments. 2377 model_create = 'NS CPMG 2-site 3D' 2378 #model_create = 'NS CPMG 2-site expanded' 2379 model_analyse = 'CR72' 2380 # Exp 1 2381 sfrq_1 = 599.8908617*1E6 2382 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2383 time_T2_1 = 0.06 2384 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2385 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2386 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2387 2388 sfrq_2 = 499.8908617*1E6 2389 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2390 time_T2_2 = 0.05 2391 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2392 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2393 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2394 2395 # Collect all exps 2396 exps = [exp_1, exp_2] 2397 2398 spins = [ 2399 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2400 ] 2401 2402 # Collect the data to be used. 2403 ds.data = [model_create, model_analyse, spins, exps] 2404 2405 # The tmp directory. None is the local directory. 2406 ds.tmpdir = ds.tmpdir 2407 2408 # The results directory. None is the local directory. 2409 #ds.resdir = None 2410 ds.resdir = ds.tmpdir 2411 2412 # Do r20_from_min_r2eff ?. 2413 ds.r20_from_min_r2eff = True 2414 2415 # Remove insignificant level. 2416 ds.insignificance = 0.0 2417 2418 # The grid search size (the number of increments per dimension). 2419 ds.GRID_INC = 8 2420 2421 # The do clustering. 2422 ds.do_cluster = False 2423 2424 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2425 # The default value is 1e-25. 2426 ds.set_func_tol = 1e-9 2427 2428 # The maximum number of iterations. 2429 # The default value is 1e7. 2430 ds.set_max_iter = 1000 2431 2432 # The verbosity level. 2433 ds.verbosity = 1 2434 2435 # The rel_change WARNING level. 2436 ds.rel_change = 0.05 2437 2438 # The plot_curves. 2439 ds.plot_curves = False 2440 2441 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2442 ds.sherekhan_input = False 2443 2444 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2445 ds.opendx = False 2446 2447 # The set r2eff err. 2448 ds.r2eff_err = 0.1 2449 2450 # The print result info. 2451 ds.print_res = False 2452 2453 # Execute the script. 2454 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2455 2456 cur_spins = ds.data[2] 2457 # Compare results. 2458 for i in range(len(cur_spins)): 2459 res_name, res_num, spin_name, params = cur_spins[i] 2460 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2461 cur_spin = return_spin(cur_spin_id) 2462 2463 grid_params = ds.grid_results[i][3] 2464 min_params = ds.min_results[i][3] 2465 # Now read the parameters. 2466 print("For spin: '%s'"%cur_spin_id) 2467 for mo_param in cur_spin.params: 2468 # The R2 is a dictionary, depending on spectrometer frequency. 2469 if isinstance(getattr(cur_spin, mo_param), dict): 2470 grid_r2 = grid_params[mo_param] 2471 min_r2 = min_params[mo_param] 2472 set_r2 = params[mo_param] 2473 for key, val in list(set_r2.items()): 2474 grid_r2_frq = grid_r2[key] 2475 min_r2_frq = min_r2[key] 2476 set_r2_frq = set_r2[key] 2477 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2478 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2479 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2480 if rel_change > ds.rel_change: 2481 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2482 print("###################################") 2483 2484 ## Make test on R2. 2485 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2486 else: 2487 grid_val = grid_params[mo_param] 2488 min_val = min_params[mo_param] 2489 set_val = params[mo_param] 2490 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2491 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2492 if rel_change > ds.rel_change: 2493 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2494 print("###################################") 2495 2496 ## Make test on parameters. 2497 if mo_param == 'dw': 2498 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2499 elif mo_param == 'kex': 2500 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2501 elif mo_param == 'pA': 2502 self.assertAlmostEqual(set_val, min_val, 3)
2503 2504
2506 """Test synthetic cpmg data. 2507 2508 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2509 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2510 """ 2511 2512 # Reset. 2513 #self.interpreter.reset() 2514 2515 ## Set Experiments. 2516 model_create = 'NS CPMG 2-site 3D' 2517 #model_create = 'NS CPMG 2-site expanded' 2518 model_analyse = 'B14' 2519 # Exp 1 2520 sfrq_1 = 599.8908617*1E6 2521 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2522 time_T2_1 = 0.06 2523 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2524 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2525 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2526 2527 sfrq_2 = 499.8908617*1E6 2528 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2529 time_T2_2 = 0.05 2530 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2531 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2532 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2533 2534 # Collect all exps 2535 exps = [exp_1, exp_2] 2536 2537 spins = [ 2538 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2539 ] 2540 2541 # Collect the data to be used. 2542 ds.data = [model_create, model_analyse, spins, exps] 2543 2544 # The tmp directory. None is the local directory. 2545 ds.tmpdir = ds.tmpdir 2546 2547 # The results directory. None is the local directory. 2548 #ds.resdir = None 2549 ds.resdir = ds.tmpdir 2550 2551 # Do r20_from_min_r2eff ?. 2552 ds.r20_from_min_r2eff = True 2553 2554 # Remove insignificant level. 2555 ds.insignificance = 0.0 2556 2557 # The grid search size (the number of increments per dimension). 2558 ds.GRID_INC = 8 2559 2560 # The do clustering. 2561 ds.do_cluster = False 2562 2563 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2564 # The default value is 1e-25. 2565 ds.set_func_tol = 1e-9 2566 2567 # The maximum number of iterations. 2568 # The default value is 1e7. 2569 ds.set_max_iter = 1000 2570 2571 # The verbosity level. 2572 ds.verbosity = 1 2573 2574 # The rel_change WARNING level. 2575 ds.rel_change = 0.05 2576 2577 # The plot_curves. 2578 ds.plot_curves = False 2579 2580 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2581 ds.sherekhan_input = False 2582 2583 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2584 ds.opendx = False 2585 2586 # The set r2eff err. 2587 ds.r2eff_err = 0.1 2588 2589 # The print result info. 2590 ds.print_res = False 2591 2592 # Execute the script. 2593 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2594 2595 cur_spins = ds.data[2] 2596 # Compare results. 2597 for i in range(len(cur_spins)): 2598 res_name, res_num, spin_name, params = cur_spins[i] 2599 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2600 cur_spin = return_spin(cur_spin_id) 2601 2602 grid_params = ds.grid_results[i][3] 2603 min_params = ds.min_results[i][3] 2604 # Now read the parameters. 2605 print("For spin: '%s'"%cur_spin_id) 2606 for mo_param in cur_spin.params: 2607 # The R2 is a dictionary, depending on spectrometer frequency. 2608 if isinstance(getattr(cur_spin, mo_param), dict): 2609 grid_r2 = grid_params[mo_param] 2610 min_r2 = min_params[mo_param] 2611 set_r2 = params[mo_param] 2612 for key, val in list(set_r2.items()): 2613 grid_r2_frq = grid_r2[key] 2614 min_r2_frq = min_r2[key] 2615 set_r2_frq = set_r2[key] 2616 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2617 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2618 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2619 if rel_change > ds.rel_change: 2620 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2621 print("###################################") 2622 2623 ## Make test on R2. 2624 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2625 else: 2626 grid_val = grid_params[mo_param] 2627 min_val = min_params[mo_param] 2628 set_val = params[mo_param] 2629 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2630 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2631 if rel_change > ds.rel_change: 2632 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2633 print("###################################") 2634 2635 ## Make test on parameters. 2636 if mo_param == 'dw': 2637 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2638 elif mo_param == 'kex': 2639 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2640 elif mo_param == 'pA': 2641 self.assertAlmostEqual(set_val, min_val, 6)
2642 2643
2645 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2646 2647 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2648 """ 2649 2650 # Reset. 2651 #self.interpreter.reset() 2652 2653 ## Set Experiments. 2654 model_create = 'NS CPMG 2-site 3D' 2655 #model_create = 'NS CPMG 2-site expanded' 2656 model_analyse = 'CR72' 2657 2658 # Exp 1 2659 sfrq_1 = 599.8908617*1E6 2660 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2661 time_T2_1 = 0.06 2662 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2663 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2664 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2665 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2666 2667 sfrq_2 = 499.8908617*1E6 2668 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2669 time_T2_2 = 0.05 2670 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2671 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2672 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2673 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2674 2675 # Collect all exps 2676 exps = [exp_1, exp_2] 2677 2678 spins = [ 2679 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2680 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2681 ] 2682 2683 # Collect the data to be used. 2684 ds.data = [model_create, model_analyse, spins, exps] 2685 2686 # The tmp directory. None is the local directory. 2687 ds.tmpdir = ds.tmpdir 2688 2689 # The results directory. None is the local directory. 2690 #ds.resdir = None 2691 ds.resdir = ds.tmpdir 2692 2693 # Do r20_from_min_r2eff ?. 2694 ds.r20_from_min_r2eff = True 2695 2696 # Remove insignificant level. 2697 ds.insignificance = 0.0 2698 2699 # The grid search size (the number of increments per dimension). 2700 ds.GRID_INC = 13 2701 2702 # The do clustering. 2703 ds.do_cluster = True 2704 2705 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2706 # The default value is 1e-25. 2707 ds.set_func_tol = 1e-8 2708 2709 # The maximum number of iterations. 2710 # The default value is 1e7. 2711 ds.set_max_iter = 10000 2712 2713 # The verbosity level. 2714 ds.verbosity = 1 2715 2716 # The rel_change WARNING level. 2717 ds.rel_change = 0.05 2718 2719 # The plot_curves. 2720 ds.plot_curves = False 2721 2722 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2723 ds.sherekhan_input = False 2724 2725 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2726 ds.opendx = False 2727 2728 # The set r2eff err. 2729 ds.r2eff_err = 0.1 2730 2731 # The print result info. 2732 ds.print_res = False 2733 2734 # Execute the script. 2735 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2736 2737 cur_spins = ds.data[2] 2738 # Compare results. 2739 for i in range(len(cur_spins)): 2740 res_name, res_num, spin_name, params = cur_spins[i] 2741 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2742 cur_spin = return_spin(cur_spin_id) 2743 2744 grid_params = ds.grid_results[i][3] 2745 2746 # Extract the clust results. 2747 min_params = ds.clust_results[i][3] 2748 # Now read the parameters. 2749 print("For spin: '%s'"%cur_spin_id) 2750 for mo_param in cur_spin.params: 2751 # The R2 is a dictionary, depending on spectrometer frequency. 2752 if isinstance(getattr(cur_spin, mo_param), dict): 2753 grid_r2 = grid_params[mo_param] 2754 min_r2 = min_params[mo_param] 2755 set_r2 = params[mo_param] 2756 for key, val in list(set_r2.items()): 2757 grid_r2_frq = grid_r2[key] 2758 min_r2_frq = min_r2[key] 2759 set_r2_frq = set_r2[key] 2760 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2761 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2762 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2763 if rel_change > ds.rel_change: 2764 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2765 print("###################################") 2766 2767 ## Make test on R2. 2768 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2769 else: 2770 grid_val = grid_params[mo_param] 2771 min_val = min_params[mo_param] 2772 set_val = params[mo_param] 2773 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2774 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2775 if rel_change > ds.rel_change: 2776 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2777 print("###################################") 2778 2779 ## Make test on parameters. 2780 if mo_param == 'dw': 2781 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2782 elif mo_param == 'kex': 2783 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2784 elif mo_param == 'pA': 2785 self.assertAlmostEqual(set_val, min_val, 2)
2786 2787
2789 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2790 2791 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2792 """ 2793 2794 # Reset. 2795 #self.interpreter.reset() 2796 2797 ## Set Experiments. 2798 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2799 model_analyse = 'CR72' 2800 # Exp 1 2801 sfrq_1 = 599.8908617*1E6 2802 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2803 time_T2_1 = 0.06 2804 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2805 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2806 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2807 2808 sfrq_2 = 499.8908617*1E6 2809 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2810 time_T2_2 = 0.05 2811 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2812 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2813 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2814 2815 # Collect all exps 2816 exps = [exp_1, exp_2] 2817 2818 spins = [ 2819 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2820 ] 2821 2822 # Collect the data to be used. 2823 ds.data = [model_create, model_analyse, spins, exps] 2824 2825 # The tmp directory. None is the local directory. 2826 ds.tmpdir = ds.tmpdir 2827 2828 # The results directory. None is the local directory. 2829 #ds.resdir = None 2830 ds.resdir = ds.tmpdir 2831 2832 # Do r20_from_min_r2eff ?. 2833 ds.r20_from_min_r2eff = True 2834 2835 # Remove insignificant level. 2836 ds.insignificance = 0.0 2837 2838 # The grid search size (the number of increments per dimension). 2839 ds.GRID_INC = None 2840 2841 # The do clustering. 2842 ds.do_cluster = False 2843 2844 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2845 # The default value is 1e-25. 2846 ds.set_func_tol = 1e-9 2847 2848 # The maximum number of iterations. 2849 # The default value is 1e7. 2850 ds.set_max_iter = 1000 2851 2852 # The verbosity level. 2853 ds.verbosity = 1 2854 2855 # The rel_change WARNING level. 2856 ds.rel_change = 0.05 2857 2858 # The plot_curves. 2859 ds.plot_curves = False 2860 2861 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2862 ds.sherekhan_input = False 2863 2864 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2865 ds.opendx = False 2866 2867 # The set r2eff err. 2868 ds.r2eff_err = 0.1 2869 2870 # The print result info. 2871 ds.print_res = False 2872 2873 # Execute the script. 2874 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2875 2876 # Get the spins. 2877 cur_spins = ds.data[2] 2878 2879 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2880 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2881 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2882 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2883 2884 # Copy R2eff, but not the original parameters 2885 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2886 2887 # Then select model. 2888 self.interpreter.relax_disp.select_model(model=model_analyse) 2889 2890 # Define dx.map settings. 2891 ds.dx_inc = 4 2892 ds.dx_params = ['dw', 'pA', 'kex'] 2893 2894 res_name, res_num, spin_name, params = cur_spins[0] 2895 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2896 cur_spin = return_spin(cur_spin_id) 2897 2898 print("Params for dx map is") 2899 print(ds.dx_params) 2900 print("Point param for dx map is") 2901 print(ds.dx_set_val) 2902 cur_model = model_analyse.replace(' ', '_') 2903 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2904 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2905 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True) 2906 2907 ## Check for file creation 2908 # Set filepaths. 2909 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2910 map_net = ds.tmpdir+sep+file_name_map+".net" 2911 map_general = ds.tmpdir+sep+file_name_map+".general" 2912 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2913 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2914 2915 point_general = ds.tmpdir+sep+file_name_point+".general" 2916 point_point = ds.tmpdir+sep+file_name_point 2917 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2918 2919 # Test the files exists. 2920 self.assert_(access(map_cfg, F_OK)) 2921 self.assert_(access(map_net, F_OK)) 2922 self.assert_(access(map_general, F_OK)) 2923 self.assert_(access(map_par, F_OK)) 2924 self.assert_(access(map_plot, F_OK)) 2925 self.assert_(access(point_general, F_OK)) 2926 self.assert_(access(point_point, F_OK)) 2927 self.assert_(access(point_par, F_OK)) 2928 2929 # Open the files for testing. 2930 # Check the cfg file. 2931 print("\nChecking the dx map .cfg file.") 2932 res_file = [ 2933 '//'+"\n", 2934 '//'+"\n", 2935 '// time: Thu May 8 18:55:31 2014'+"\n", 2936 '//'+"\n", 2937 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2938 '//'+"\n", 2939 '//'+"\n", 2940 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2941 '// title: value = Control Panel'+"\n", 2942 '//'+"\n", 2943 '// workspace: width = 251, height = 142'+"\n", 2944 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2945 '//'+"\n", 2946 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2947 '// selections: maximum = 2, current = 0 '+"\n", 2948 '// option[0]: name = "Colour", value = 1'+"\n", 2949 '// option[1]: name = "Grey", value = 2'+"\n", 2950 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2951 '// label: value = Colour Selector'+"\n", 2952 '//'+"\n", 2953 '// node Image[3]:'+"\n", 2954 '// title: value = Surface'+"\n", 2955 '// depth: value = 24'+"\n", 2956 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2957 ] 2958 file = open(map_cfg, 'r') 2959 lines = file.readlines() 2960 file.close() 2961 for i in range(len(res_file)): 2962 # Skip time point 2963 if i == 2: 2964 continue 2965 self.assertEqual(res_file[i], lines[i]) 2966 2967 print("\nChecking the dx map .general file.") 2968 res_file = [ 2969 'file = CR72_map_1_N'+"\n", 2970 'grid = 5 x 5 x 5'+"\n", 2971 'format = ascii'+"\n", 2972 'interleaving = field'+"\n", 2973 'majority = row'+"\n", 2974 'field = data'+"\n", 2975 'structure = scalar'+"\n", 2976 'type = float'+"\n", 2977 'dependency = positions'+"\n", 2978 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2979 ''+"\n", 2980 'end'+"\n", 2981 ] 2982 file = open(map_general, 'r') 2983 lines = file.readlines() 2984 file.close() 2985 for i in range(len(res_file)): 2986 # Skip time point 2987 #if i == 2: 2988 # continue 2989 self.assertEqual(res_file[i], lines[i]) 2990 2991 print("\nChecking the dx point .general file.") 2992 res_file = [ 2993 'file = CR72_point_1_N'+"\n", 2994 'points = 2'+"\n", 2995 'format = ascii'+"\n", 2996 'interleaving = field'+"\n", 2997 'field = locations, field0'+"\n", 2998 'structure = 3-vector, scalar'+"\n", 2999 'type = float, float'+"\n", 3000 ''+"\n", 3001 'end'+"\n", 3002 ] 3003 file = open(point_general, 'r') 3004 lines = file.readlines() 3005 file.close() 3006 for i in range(len(res_file)): 3007 # Skip time point 3008 #if i == 2: 3009 # continue 3010 self.assertEqual(res_file[i], lines[i]) 3011 3012 print("\nChecking the dx point point file.") 3013 res_file = [ 3014 '0.8 3.92 0.39964 1'+"\n", 3015 '0.76981 3.9169 0.41353 1'+"\n", 3016 ] 3017 file = open(point_point, 'r') 3018 lines = file.readlines() 3019 file.close() 3020 for i in range(len(res_file)): 3021 # Skip time point 3022 #if i == 2: 3023 # continue 3024 self.assertEqual(res_file[i], lines[i]) 3025 3026 print("\nChecking the dx point par file.") 3027 res_file = [ 3028 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3029 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3030 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 3031 ] 3032 res_file2 = [ 3033 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3034 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3035 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 3036 ] # Python 2.5 and 3.1. 3037 file = open(point_par, 'r') 3038 lines = file.readlines() 3039 file.close() 3040 for i in range(len(res_file)): 3041 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 3042 self.assertEqual(res_file[i], lines[i]) 3043 3044 print("\nChecking the matplotlib surface plot file.") 3045 res_file = [ 3046 'from copy import deepcopy'+"\n", 3047 'import numpy as np'+"\n", 3048 'import scipy.interpolate'+"\n", 3049 'from numpy.ma import masked_where'+"\n", 3050 ''+"\n", 3051 'from mpl_toolkits.mplot3d import axes3d'+"\n", 3052 'import matplotlib.pyplot as plt'+"\n", 3053 'from matplotlib import cm'+"\n", 3054 ''+"\n", 3055 '# Open file and get header.'+"\n", 3056 'mapfile_name = "%s.par"'%file_name_map+"\n", 3057 'pointfile_name = "%s.par"'%file_name_point+"\n", 3058 ''+"\n", 3059 ] 3060 file = open(map_plot, 'r') 3061 lines = file.readlines() 3062 file.close() 3063 for i in range(len(res_file)): 3064 self.assertEqual(res_file[i], lines[i])
3065 3066
3068 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 3069 3070 # Reset. 3071 self.interpreter.reset() 3072 3073 # Load the base data. 3074 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 3075 self.interpreter.state.load(data_path+sep+'r2eff_values') 3076 3077 # The type. 3078 curve_type = get_curve_type(id='500_133.33.in') 3079 self.assertEqual(curve_type, 'fixed time')
3080 3081
3082 - def test_curve_type_r1rho_exponential(self, model=None):
3083 """Test the curve type detection using the 'M61' exponential test data.""" 3084 3085 # Reset. 3086 self.interpreter.reset() 3087 3088 # Load the base data. 3089 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 3090 self.interpreter.state.load(data_path+sep+'r2eff_values') 3091 3092 # The type. 3093 curve_type = get_curve_type(id='nu_2000_ncyc9') 3094 self.assertEqual(curve_type, 'exponential')
3095 3096
3097 - def test_curve_type_r1rho_fixed_time(self, model=None):
3098 """Test the curve type detection using the 'TP02' fixed time test data.""" 3099 3100 # Reset. 3101 self.interpreter.reset() 3102 3103 # Load the base data. 3104 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 3105 self.interpreter.state.load(data_path+sep+'r2eff_values') 3106 3107 # The type. 3108 curve_type = get_curve_type(id='nu_1000.0_500MHz') 3109 self.assertEqual(curve_type, 'fixed time')
3110 3111
3112 - def test_dpl94_data_to_dpl94(self):
3113 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 3114 3115 # Fixed time variable. 3116 ds.fixed = True 3117 3118 # Execute the script. 3119 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 3120 3121 # The original parameters. 3122 i0 = [100000.0, 20000.0] 3123 r1rho_prime = [2.25, 24.0] 3124 pA = 0.7 3125 kex = 1000.0 3126 delta_omega = [1.0, 2.0] 3127 phi_ex = [] 3128 for i in range(2): 3129 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3130 3131 # Switch to the 'DPL94' model data pipe, then check for each spin. 3132 self.interpreter.pipe.switch('DPL94 - relax_disp') 3133 spin_index = 0 3134 for spin, spin_id in spin_loop(return_id=True): 3135 # Printout. 3136 print("\nSpin %s." % spin_id) 3137 3138 # Check the fitted parameters. 3139 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3140 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3141 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3142 3143 # Increment the spin index. 3144 spin_index += 1
3145 3146
3147 - def test_dx_map_clustered(self):
3148 """Test making dx_map for residues under clustered calculation. 3149 3150 This uses CPMG data from: 3151 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3152 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3153 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3154 """ 3155 3156 # Define path to data 3157 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3158 3159 # Read data. 3160 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3161 3162 # Get residue of interest. 3163 cur_spin_id = ":%i@%s"%(52, 'N') 3164 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3165 3166 # Get the spin container. 3167 cur_spin = return_spin(cur_spin_id) 3168 3169 # Get the chi2 value 3170 pre_chi2 = cur_spin.chi2 3171 3172 # Then do a local minimisation. 3173 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3174 self.interpreter.minimise.calculate() 3175 3176 # Get the chi2 value after calculation. 3177 calc_chi2 = cur_spin.chi2 3178 3179 # Assert calculation is equal. 3180 self.assertAlmostEqual(pre_chi2, calc_chi2) 3181 3182 # Define dx.map settings. 3183 dx_inc = 2 3184 dx_inc_sides = dx_inc / 2 3185 3186 dx_params = ['dw', 'pA', 'kex'] 3187 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3188 3189 print("Params for dx map is") 3190 print(dx_params) 3191 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3192 print(dx_point_clustered_min) 3193 3194 # Define file_names. 3195 cur_model = 'CR72' 3196 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3197 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3198 3199 # Step-size of parameter is 10 % 3200 param_delta = 0.1 3201 3202 # Determine bounds for lower and upper 3203 lower = [] 3204 upper = [] 3205 for i, param_val in enumerate(dx_point_clustered_min): 3206 param = dx_params[i] 3207 step_val = param_delta * param_val 3208 step_length = step_val * dx_inc_sides 3209 3210 # Calculate value 3211 low_val = param_val - step_length 3212 lower.append(low_val) 3213 3214 upp_val = param_val + step_length 3215 upper.append(upp_val) 3216 3217 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3218 3219 # If the number of increments are 2, there will be 3 point calculations per parameter. 3220 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3221 dx_param_indexes = dx_inc + 1 3222 dx_point_index = dx_inc_sides + 1 3223 3224 # Find the line number. 3225 line = 1 3226 for i in range(1, dx_param_indexes + 1): 3227 for j in range(1, dx_param_indexes + 1): 3228 for k in range(1, dx_param_indexes + 1): 3229 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3230 line_chi2 = line 3231 # Add to line counter. 3232 line += 1 3233 3234 # Define temporary folder. 3235 result_dir = self.tmpdir 3236 3237 # For testing. 3238 #result_dir = None 3239 #lower = None 3240 #upper = None 3241 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3242 3243 3244 # Then do the map. 3245 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3246 3247 # Print where to locate values. 3248 nr_chi2_val = dx_param_indexes**3 3249 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3250 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3251 3252 ## Check for file creation 3253 # Set filepaths. 3254 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3255 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3256 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3257 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3258 3259 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3260 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3261 3262 # Test the files exists. 3263 self.assert_(access(map_cfg, F_OK)) 3264 self.assert_(access(map_net, F_OK)) 3265 self.assert_(access(map_general, F_OK)) 3266 self.assert_(access(point_general, F_OK)) 3267 self.assert_(access(point_point, F_OK)) 3268 3269 # Open the file, and assert the chi2 value is as expected. 3270 get_data = extract_data(file=map_name) 3271 3272 # Extract line 0, column 0. 3273 test = float(get_data[line_chi2-1][0]) 3274 3275 # Assert. 3276 self.assertAlmostEqual(test, pre_chi2, 6)
3277 3278
3280 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3281 3282 U{Task #7860<https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value. 3283 3284 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 3285 """ 3286 3287 # Define path to data 3288 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3289 3290 # Read data. 3291 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3292 3293 # Get residue of interest. 3294 cur_spin_id = ":%i@%s"%(65, 'N') 3295 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3296 3297 # Get the spin container. 3298 cur_spin = return_spin(cur_spin_id) 3299 3300 # Get the chi2 value 3301 pre_chi2 = cur_spin.chi2 3302 3303 # Then do a local minimisation. 3304 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3305 self.interpreter.minimise.calculate() 3306 3307 # Get the chi2 value after calculation. 3308 calc_chi2 = cur_spin.chi2 3309 3310 # Assert calculation is equal. 3311 self.assertAlmostEqual(pre_chi2, calc_chi2) 3312 3313 # Define dx.map settings. 3314 dx_inc = 2 3315 dx_params = ['dw', 'k_AB', 'r2a'] 3316 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3317 3318 print("Params for dx map is") 3319 print(dx_params) 3320 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3321 print(dx_point_clustered_min) 3322 3323 # Define file_names. 3324 cur_model = 'TSMFK01' 3325 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3326 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3327 3328 # Determine bounds for lower and upper 3329 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3330 upper = [19.0, 2.4, 9.5] 3331 3332 # Define temporary folder. 3333 result_dir = self.tmpdir 3334 3335 # For testing. 3336 #result_dir = None 3337 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3338 3339 # Then do the map. 3340 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True) 3341 3342 # Print where to locate values. 3343 nr_chi2_val = (dx_inc + 1)**3 3344 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3345 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3346 3347 ## Check for file creation 3348 # Set filepaths. 3349 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3350 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3351 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3352 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3353 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3354 3355 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3356 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3357 3358 # Test the files exists. 3359 self.assert_(access(map_cfg, F_OK)) 3360 self.assert_(access(map_net, F_OK)) 3361 self.assert_(access(map_general, F_OK)) 3362 self.assert_(access(map_par, F_OK)) 3363 self.assert_(access(point_general, F_OK)) 3364 self.assert_(access(point_point, F_OK)) 3365 3366 print("\nParams for dx map is") 3367 print(dx_params) 3368 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3369 print(dx_point_clustered_min, "\n") 3370 3371 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3372 get_data = extract_data(file=map_par) 3373 3374 # Extract line 1, column 9. 3375 test = float(get_data[1][9]) 3376 3377 # Print data if map contain a lower value than the global minimised value. 3378 if test < pre_chi2: 3379 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3380 for line in get_data: 3381 print(line)
3382 3383 # Assert that the initial global chi2 is lower than the map value. 3384 3385 # The following test was taken out, since this a particular interesting case. 3386 # There exist a double minimum, where relax has not found the global minimum. 3387 # This is due to not grid searching for R2A, but using the minimum 3388 #self.assert_(pre_chi2 < test) 3389 3390
3391 - def test_estimate_r2eff_err(self):
3392 """Test the user function for estimating R2eff errors from exponential curve fitting. 3393 3394 This follows Task 7822. 3395 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3396 3397 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3398 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3399 """ 3400 3401 # Cluster residues 3402 cluster_ids = [ 3403 ":13@N", 3404 ":15@N", 3405 ":16@N", 3406 ":25@N", 3407 ":26@N", 3408 ":28@N", 3409 ":39@N", 3410 ":40@N", 3411 ":41@N", 3412 ":43@N", 3413 ":44@N", 3414 ":45@N", 3415 ":49@N", 3416 ":52@N", 3417 ":53@N"] 3418 3419 # Load the data. 3420 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3421 3422 # The dispersion models. 3423 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3424 3425 # The grid search size (the number of increments per dimension). 3426 GRID_INC = None 3427 3428 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3429 MC_NUM = 3 3430 3431 # Model selection technique. 3432 MODSEL = 'AIC' 3433 3434 # Execute the auto-analysis (fast). 3435 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3436 OPT_FUNC_TOL = 1e-25 3437 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3438 OPT_MAX_ITERATIONS = 10000000 3439 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3440 3441 result_dir_name = ds.tmpdir 3442 3443 # Make all spins free 3444 for curspin in cluster_ids: 3445 self.interpreter.relax_disp.cluster('free spins', curspin) 3446 # Shut them down 3447 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3448 3449 # Select only a subset of spins for global fitting 3450 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3451 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3452 3453 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3454 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3455 3456 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3457 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3458 3459 # Set the model. 3460 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3461 3462 # Check if intensity errors have already been calculated. 3463 check_intensity_errors() 3464 3465 # Do a grid search. 3466 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3467 3468 # Minimise. 3469 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3470 3471 # Estimate R2eff errors. 3472 self.interpreter.relax_disp.r2eff_err_estimate() 3473 3474 r1_fit = True 3475 3476 # Run the analysis. 3477 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3478 3479 # Verify the data. 3480 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3481 3482
3484 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3485 3486 This follows Task 7822. 3487 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3488 3489 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3490 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3491 """ 3492 3493 # Cluster residues 3494 cluster_ids = [ 3495 ":13@N", 3496 ":15@N", 3497 ":16@N", 3498 ":25@N", 3499 ":26@N", 3500 ":28@N", 3501 ":39@N", 3502 ":40@N", 3503 ":41@N", 3504 ":43@N", 3505 ":44@N", 3506 ":45@N", 3507 ":49@N", 3508 ":52@N", 3509 ":53@N"] 3510 3511 # Load the data. 3512 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3513 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3514 3515 # Set pipe name, bundle and type. 3516 pipe_name = 'base pipe' 3517 pipe_bundle = 'relax_disp' 3518 pipe_type = 'relax_disp' 3519 3520 # Create the data pipe. 3521 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3522 3523 file = data_path + '1_setup_r1rho_GUI.py' 3524 self.interpreter.script(file=file, dir=None) 3525 3526 # The dispersion models. 3527 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3528 3529 # The grid search size (the number of increments per dimension). 3530 GRID_INC = None 3531 3532 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3533 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3534 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3535 EXP_MC_NUM = -1 3536 3537 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3538 MC_NUM = 3 3539 3540 # Model selection technique. 3541 MODSEL = 'AIC' 3542 3543 # Execute the auto-analysis (fast). 3544 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3545 OPT_FUNC_TOL = 1e-25 3546 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3547 OPT_MAX_ITERATIONS = 10000000 3548 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3549 3550 # Make all spins free 3551 #for curspin in cluster_ids: 3552 # self.interpreter.relax_disp.cluster('free spins', curspin) 3553 # # Shut them down 3554 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3555 3556 # Make all spins free 3557 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3558 3559 # Select only a subset of spins for global fitting 3560 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3561 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3562 3563 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3564 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3565 3566 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3567 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3568 3569 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3570 print(spin_id) 3571 3572 result_dir_name = self.tmpdir 3573 r1_fit = True 3574 3575 # Run the analysis. 3576 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3577 3578 # Verify the data. 3579 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3580 3581
3583 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3584 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3585 3586 This follows Task 7822. 3587 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3588 3589 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3590 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3591 3592 NOTE: The difference in the methods was due to a bug in relax! 3593 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3594 3595 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3596 """ 3597 3598 # Define data path. 3599 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3600 3601 # Create pipe. 3602 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3603 3604 # Read results for 2000 MC simulations. 3605 self.interpreter.results.read(prev_data_path + sep + 'results') 3606 3607 # Start dic. 3608 my_dic = {} 3609 param_key_list = [] 3610 3611 # Do boot strapping ? 3612 do_boot = True 3613 if do_boot: 3614 min_algor = 'Newton' 3615 min_options = () 3616 sim_boot = 200 3617 scaling_list = [1.0, 1.0] 3618 3619 # First check sim values. 3620 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3621 # Add key to dic. 3622 my_dic[spin_id] = {} 3623 3624 # Loop over sim. 3625 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3626 # Loop over all exp type. 3627 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3628 # Generate the param_key. 3629 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3630 r2eff_sim_point = r2eff_sim[param_key] 3631 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3632 3633 # Assert point are higher than 0.0. 3634 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3635 #print(point_info) 3636 self.assert_(r2eff_sim_point > 0.0) 3637 self.assert_(i0_sim_point > 0.0) 3638 3639 # Get the data. 3640 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3641 # Generate spin string. 3642 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3643 3644 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3645 # Generate the param_key. 3646 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3647 3648 # Loop over all sim, and collect data. 3649 r2eff_sim_l = [] 3650 i0_sim_l = [] 3651 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3652 i0_sim = cur_spin.i0_sim[i] 3653 3654 r2eff_sim_i = r2eff_sim[param_key] 3655 r2eff_sim_l.append(r2eff_sim_i) 3656 i0_sim_i = i0_sim[param_key] 3657 i0_sim_l.append(i0_sim_i) 3658 3659 # Take the standard deviation of all values. 3660 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3661 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3662 3663 # Append key. 3664 param_key_list.append(param_key) 3665 3666 # Add key to dic. 3667 my_dic[spin_id][param_key] = {} 3668 3669 # Get the value. 3670 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3671 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3672 i0 = getattr(cur_spin, 'i0')[param_key] 3673 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3674 3675 # Save to dic. 3676 my_dic[spin_id][param_key]['r2eff'] = r2eff 3677 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3678 my_dic[spin_id][param_key]['i0'] = i0 3679 my_dic[spin_id][param_key]['i0_err'] = i0_err 3680 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3681 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3682 3683 # Assert values are equal 3684 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3685 self.assertAlmostEqual(i0_sim_err, i0_err) 3686 3687 if do_boot: 3688 values = [] 3689 errors = [] 3690 times = [] 3691 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3692 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3693 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3694 times.append(time) 3695 3696 # Convert to numpy array. 3697 values = asarray(values) 3698 errors = asarray(errors) 3699 times = asarray(times) 3700 3701 R_m_sim_l = [] 3702 I0_m_sim_l = [] 3703 for j in range(sim_boot): 3704 if j in range(0, 100000, 100): 3705 print("Simulation %i"%j) 3706 # Start minimisation. 3707 3708 # Produce errors 3709 I_err = [] 3710 for j, error in enumerate(errors): 3711 I_error = gauss(values[j], error) 3712 I_err.append(I_error) 3713 # Convert to numpy array. 3714 I_err = asarray(I_err) 3715 3716 x0 = [r2eff, i0] 3717 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3718 3719 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3720 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3721 R_m_sim_l.append(R_m_sim_j) 3722 I0_m_sim_l.append(I0_m_sim_j) 3723 3724 # Get stats on distribution. 3725 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3726 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3727 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3728 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3729 3730 3731 # A new data pipe. 3732 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3733 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3734 3735 # Delete old errors. 3736 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3737 delattr(cur_spin, 'r2eff_err') 3738 delattr(cur_spin, 'i0_err') 3739 3740 # Set the model. 3741 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3742 3743 # Estimate R2eff and errors. 3744 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3745 3746 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3747 # Generate spin string. 3748 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3749 3750 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3751 # Generate the param_key. 3752 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3753 3754 # Get the value. 3755 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3756 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3757 i0_est = getattr(cur_spin, 'i0')[param_key] 3758 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3759 3760 # Get from dic. 3761 r2eff = my_dic[spin_id][param_key]['r2eff'] 3762 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3763 i0 = my_dic[spin_id][param_key]['i0'] 3764 i0_err = my_dic[spin_id][param_key]['i0_err'] 3765 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3766 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3767 3768 if do_boot: 3769 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3770 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3771 else: 3772 r2eff_boot_err = 0.0 3773 i0_boot_err = 0.0 3774 3775 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3776 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3777 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3778 3779 3780 # Now do it manually. 3781 estimate_r2eff(method='scipy.optimize.leastsq') 3782 3783 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3784 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3785 3786 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3787 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3788 3789 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3790 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3791 3792 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3793 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3794 3795 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3796 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3797 3798 3799
3800 - def test_exp_fit(self):
3801 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3802 3803 # Execute the script. 3804 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3805 3806 # The original exponential curve parameters. 3807 res_data = [ 3808 [15., 10., 20000., 25000.], 3809 [12., 11., 50000., 51000.], 3810 [17., 9., 100000., 96000.] 3811 ] 3812 3813 # List of parameters which do not belong to the model. 3814 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3815 3816 # Checks for each residue. 3817 for i in range(len(res_data)): 3818 # Printout. 3819 print("\nResidue number %s." % (i+1)) 3820 3821 # Check the fitted parameters. 3822 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3823 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3824 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3825 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3826 3827 # Check the simulation errors. 3828 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3829 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3830 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3831 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3832 3833 # Check that certain parameters are not present. 3834 for param in blacklist: 3835 print("\tChecking for the absence of the '%s' parameter." % param) 3836 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3837 3838 # Check the clustering information. 3839 self.assert_(hasattr(cdp, 'clustering')) 3840 keys = ['free spins', 'cluster'] 3841 for key in keys: 3842 self.assert_(key in cdp.clustering) 3843 self.assert_('test' not in cdp.clustering) 3844 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3845 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3846 3847
3848 - def test_finite_value(self):
3849 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3850 3851 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3852 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3853 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3854 3855 scaling_list = [1.0, 1.0] 3856 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3857 3858 R = - 500. 3859 I0 = 1000. 3860 params = [R, I0] 3861 3862 chi2 = model.func(params) 3863 3864 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3865 self.assertNotEqual(chi2, inf)
3866 3867
3868 - def test_hansen_catia_input(self):
3869 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3870 3871 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3872 """ 3873 3874 # Load the R2eff results file. 3875 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3876 self.interpreter.results.read(file_name) 3877 self.interpreter.deselect.spin(':4') 3878 3879 # The spin isotopes. 3880 self.interpreter.spin.isotope("15N") 3881 3882 # Generate the input files. 3883 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3884 3885 # Check the r2eff set files. 3886 print("\nChecking the R2eff input set files.") 3887 files = ['data_set_500.inp', 'data_set_500.inp'] 3888 for file in files: 3889 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3890 data_set_500 = [ 3891 "ID=500\n", 3892 "Sfrq = 500\n", 3893 "Temperature = 0.0\n", 3894 "Nucleus = N15\n", 3895 "Couplednucleus = H1\n", 3896 "Time_equil = 0.0\n", 3897 "Pwx_cp = 0.0\n", 3898 "Taub = 0.0\n", 3899 "Time_T2 = 0.03\n", 3900 "Xcar = 0.0\n", 3901 "Seqfil = CW_CPMG\n", 3902 "Minerror = (2.%;0.5/s)\n", 3903 "Basis = (Iph_7)\n", 3904 "Format = (0;1;2)\n", 3905 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3906 "Data = (\n", 3907 " [70N;spin_70_N_500.cpmg];\n", 3908 " [71N;spin_71_N_500.cpmg];\n", 3909 ")\n", 3910 ] 3911 file = open(ds.tmpdir+sep+files[0]) 3912 lines = file.readlines() 3913 file.close() 3914 for i in range(len(data_set_500)): 3915 # Skip the data directory, as this is a random file name. 3916 if i == 14: 3917 continue 3918 3919 self.assertEqual(data_set_500[i], lines[i]) 3920 3921 # Check the r2eff files. 3922 print("\nChecking the R2eff input files.") 3923 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3924 for file in files: 3925 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3926 spin_70_N_500 = [ 3927 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3928 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3929 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3930 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3931 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3932 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3933 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3934 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3935 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3936 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3937 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3938 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3939 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3940 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3941 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3942 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3943 ] 3944 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3945 lines = file.readlines() 3946 file.close() 3947 for i in range(len(lines)): 3948 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3949 for i in range(len(spin_70_N_500)): 3950 self.assertEqual(spin_70_N_500[i], lines[i]) 3951 3952 # Check the main file. 3953 print("\nChecking the main CATIA execution file.") 3954 main_file = [ 3955 "ReadDataset(data_set_500.inp)\n", 3956 "ReadDataset(data_set_800.inp)\n", 3957 "ReadParam_Global(ParamGlobal.inp)\n", 3958 "ReadParam_Local(ParamSet1.inp)\n", 3959 "\n", 3960 "FreeLocalParam(all;Omega;false)\n", 3961 "FreeLocalParam(all;R1iph_500;false)\n", 3962 "FreeLocalParam(all;R1iph_800;false)\n", 3963 "\n", 3964 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3965 "\n", 3966 "PrintParam(output/GlobalParam.fit;global)\n", 3967 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3968 "PrintData(output/)\n", 3969 "\n", 3970 "ChiSq(all;all)\n", 3971 "exit(0)\n" 3972 ] 3973 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3974 lines = file.readlines() 3975 file.close() 3976 for i in range(len(main_file)): 3977 self.assertEqual(main_file[i], lines[i])
3978 3979
3981 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3982 3983 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3984 """ 3985 3986 # Set the model. 3987 ds.models = [ 3988 MODEL_NOREX, 3989 MODEL_LM63, 3990 MODEL_CR72, 3991 MODEL_IT99 3992 ] 3993 3994 # Execute the script. 3995 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3996 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3997 3998 # The R20 keys. 3999 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4000 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4001 4002 # The 'No Rex' model checks. 4003 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4004 spin70 = return_spin(":70") 4005 spin71 = return_spin(":71") 4006 print("\n\nOptimised parameters:\n") 4007 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4008 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4009 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4010 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4011 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4012 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4013 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4014 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4015 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4016 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4017 4018 # The 'LM63' model checks. 4019 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4020 spin70 = return_spin(":70") 4021 spin71 = return_spin(":71") 4022 print("\n\nOptimised parameters:\n") 4023 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4024 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4025 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4026 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4027 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4028 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4029 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4030 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4031 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4032 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4033 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4034 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4035 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4036 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4037 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4038 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4039 4040 # The 'CR72' model checks. 4041 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4042 spin70 = return_spin(":70") 4043 spin71 = return_spin(":71") 4044 print("\n\nOptimised parameters:\n") 4045 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4046 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4047 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4048 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4049 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4050 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4051 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4052 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4053 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4054 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4055 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4056 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4057 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4058 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4059 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4060 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4061 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4062 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4063 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4064 4065
4067 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 4068 4069 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4070 """ 4071 4072 # Set the model and numeric flag. 4073 ds.models = [ 4074 MODEL_NOREX, 4075 MODEL_CR72, 4076 MODEL_NS_CPMG_2SITE_EXPANDED 4077 ] 4078 ds.numeric_only = True 4079 4080 # Execute the script. 4081 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4082 4083 # The R20 keys. 4084 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4085 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4086 4087 # The 'No Rex' model checks. 4088 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4089 spin70 = return_spin(":70") 4090 spin71 = return_spin(":71") 4091 print("\n\nOptimised parameters:\n") 4092 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4093 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4094 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4095 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4096 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4097 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4098 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 4099 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4100 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4101 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 4102 4103 # The 'CR72' model checks. 4104 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4105 spin70 = return_spin(":70") 4106 spin71 = return_spin(":71") 4107 print("\n\nOptimised parameters:\n") 4108 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4109 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4110 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4111 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4112 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4113 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4114 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4115 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4116 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4117 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4118 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4119 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4120 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4121 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4122 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4123 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4124 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4125 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4126 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4127 4128 # The 'NS CPMG 2-site expanded' model checks. 4129 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4130 spin70 = return_spin(":70") 4131 spin71 = return_spin(":71") 4132 print("\n\nOptimised parameters:\n") 4133 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4134 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4135 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4136 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4137 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4138 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4139 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4140 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4141 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4142 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4143 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4144 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4145 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4146 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4147 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4148 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4149 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4150 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4151 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4152 4153 # The final data pipe checks. 4154 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4155 spin70 = return_spin(":70") 4156 spin71 = return_spin(":71") 4157 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4158 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4159 4160
4162 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4163 4164 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4165 """ 4166 4167 # Set the model. 4168 ds.models = [ 4169 MODEL_NOREX, 4170 MODEL_LM63, 4171 MODEL_CR72, 4172 MODEL_IT99 4173 ] 4174 4175 # Execute the script. 4176 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4177 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4178 4179 # The R20 keys. 4180 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4181 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4182 4183 # The 'No Rex' model checks. 4184 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4185 spin70 = return_spin(":70") 4186 spin71 = return_spin(":71") 4187 print("\n\nOptimised parameters:\n") 4188 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4189 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4190 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4191 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4192 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4193 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4194 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4195 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4196 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4197 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4198 4199 # The 'LM63' model checks. 4200 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4201 spin70 = return_spin(":70") 4202 spin71 = return_spin(":71") 4203 print("\n\nOptimised parameters:\n") 4204 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4205 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4206 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4207 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4208 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4209 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4210 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4211 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4212 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4213 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4214 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4215 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4216 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4217 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4218 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4219 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4220 4221 # The 'CR72' model checks. 4222 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4223 spin70 = return_spin(":70") 4224 spin71 = return_spin(":71") 4225 print("\n\nOptimised parameters:\n") 4226 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4227 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4228 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4229 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4230 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4231 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4232 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4233 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4234 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4235 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4236 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4237 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4238 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4239 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4240 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4241 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4242 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4243 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4244 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4245 4246
4248 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4249 4250 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4251 """ 4252 4253 # Set the model. 4254 ds.models = [ 4255 MODEL_R2EFF, 4256 MODEL_NOREX, 4257 MODEL_CR72, 4258 MODEL_NS_CPMG_2SITE_EXPANDED 4259 ] 4260 4261 # Execute the script. 4262 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4263 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4264 4265 # The R20 keys. 4266 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4267 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4268 4269 # The 'No Rex' model checks. 4270 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4271 spin4 = return_spin(":4") 4272 spin70 = return_spin(":70") 4273 spin71 = return_spin(":71") 4274 print("\n\nOptimised parameters:\n") 4275 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4276 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4277 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4278 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4279 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4280 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4281 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4282 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4283 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4284 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4285 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4286 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4287 4288 # The 'CR72' model checks. 4289 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4290 spin4 = return_spin(":4") 4291 spin70 = return_spin(":70") 4292 spin71 = return_spin(":71") 4293 print("\n\nOptimised parameters:\n") 4294 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4295 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4296 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4297 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4298 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4299 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4300 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4301 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4302 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4303 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4304 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4305 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4306 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4307 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4308 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4309 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4310 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4311 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4312 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4313 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4314 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4315 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4316 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4317 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4318 4319
4321 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4322 4323 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4324 """ 4325 4326 # Base data setup. 4327 self.setup_hansen_cpmg_data(model='CR72') 4328 4329 # Alias the spins. 4330 spin70 = return_spin(":70") 4331 spin71 = return_spin(":71") 4332 4333 # The R20 keys. 4334 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4335 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4336 4337 # Set the initial parameter values. 4338 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4339 spin70.pA = 0.9 4340 spin70.dw = 6.0 4341 spin70.kex = 1500.0 4342 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4343 spin71.pA = 0.9 4344 spin71.dw = 4.0 4345 spin71.kex = 1900.0 4346 4347 # Low precision optimisation. 4348 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4349 4350 # Printout. 4351 print("\n\nOptimised parameters:\n") 4352 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4353 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4354 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4355 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4356 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4357 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4358 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4359 4360 # Checks for residue :70. 4361 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4362 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4363 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4364 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4365 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4366 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4367 4368 # Checks for residue :71. 4369 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4370 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4371 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4372 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4373 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4374 4375 # Test the conversion to k_AB from kex and pA. 4376 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4377 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4378 4379 # Test the conversion to k_BA from kex and pA. 4380 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4381 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4382 4383
4385 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4386 4387 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4388 """ 4389 4390 # Base data setup. 4391 self.setup_hansen_cpmg_data(model='CR72 full') 4392 4393 # Alias the spins. 4394 spin70 = return_spin(":70") 4395 spin71 = return_spin(":71") 4396 4397 # The R20 keys. 4398 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4399 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4400 4401 # Set the initial parameter values. 4402 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4403 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4404 spin70.pA = 0.9 4405 spin70.dw = 6.0 4406 spin70.kex = 1500.0 4407 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4408 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4409 spin71.pA = 0.9 4410 spin71.dw = 4.0 4411 spin71.kex = 1900.0 4412 4413 # Low precision optimisation. 4414 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4415 4416 # Printout. 4417 print("\n\nOptimised parameters:\n") 4418 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4419 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4420 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4421 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4422 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4423 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4424 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4425 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4426 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4427 4428 # Checks for residue :70. 4429 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4430 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4431 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4432 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4433 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4434 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4435 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4436 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4437 4438 # Checks for residue :71. 4439 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4440 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4441 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4442 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4443 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4444 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4445 4446 # Test the conversion to k_AB from kex and pA. 4447 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4448 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4449 4450 # Test the conversion to k_BA from kex and pA. 4451 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4452 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4453 4454
4456 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4457 4458 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4459 """ 4460 4461 # Base data setup. 4462 self.setup_hansen_cpmg_data(model='IT99') 4463 4464 # Alias the spins. 4465 spin70 = return_spin(":70") 4466 spin71 = return_spin(":71") 4467 4468 # The R20 keys. 4469 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4470 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4471 4472 # Set the initial parameter values. 4473 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4474 spin70.dw = 10.0 4475 spin70.pA = 0.5 4476 spin70.tex = 1000.09 4477 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4478 spin71.dw = 10.0 4479 spin71.pA = 0.95 4480 spin71.tex = 0.1 4481 4482 # Low precision optimisation. 4483 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4484 4485 # Printout. 4486 print("\n\nOptimised parameters:\n") 4487 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4488 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4489 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4490 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4491 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4492 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4493 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4494 4495 # Checks for residue :70. 4496 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4497 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4498 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4499 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4500 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4501 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4502 4503 # Checks for residue :71. 4504 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4505 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4506 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4507 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4508 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4509 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4510 4511
4513 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4514 4515 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4516 """ 4517 4518 # Base data setup. 4519 self.setup_hansen_cpmg_data(model='LM63') 4520 4521 # Alias the spins. 4522 spin70 = return_spin(":70") 4523 spin71 = return_spin(":71") 4524 4525 # The R20 keys. 4526 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4527 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4528 4529 # Set the initial parameter values. 4530 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4531 spin70.phi_ex = 0.3 4532 spin70.kex = 5000.0 4533 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4534 spin71.phi_ex = 0.1 4535 spin71.kex = 2500.0 4536 4537 # Low precision optimisation. 4538 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4539 4540 # Printout. 4541 print("\n\nOptimised parameters:\n") 4542 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4543 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4544 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4545 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4546 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4547 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4548 4549 # Checks for residue :70. 4550 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4551 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4552 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4553 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4554 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4555 4556 # Checks for residue :71. 4557 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4558 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4559 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4560 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4561 4562
4564 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4565 4566 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4567 """ 4568 4569 # Base data setup. 4570 self.setup_hansen_cpmg_data(model='LM63 3-site') 4571 4572 # Alias the spins. 4573 spin70 = return_spin(":70") 4574 spin71 = return_spin(":71") 4575 4576 # The R20 keys. 4577 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4578 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4579 4580 ## Set the initial parameter values. 4581 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4582 spin70.phi_ex_B = 0.14872003058250227 4583 spin70.phi_ex_C = 0.1319419923472704 4584 spin70.kB = 4103.672910444741 4585 spin70.kC = 7029.001690726248 4586 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4587 spin71.phi_ex_B = 0.04013553485505605 4588 spin71.phi_ex_C = 0.020050748406928887 4589 spin71.kB = 4045.3007136121364 4590 spin71.kC = 3586.38798270774 4591 4592 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4593 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4594 4595 # Low precision optimisation. 4596 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4597 4598 # Printout. 4599 print("\n\nOptimised parameters:\n") 4600 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4601 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4602 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4603 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4604 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4605 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4606 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4607 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4608 4609 # Checks for residue :70. 4610 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4611 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4612 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4613 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4614 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4615 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4616 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4617 4618 # Checks for residue :71. 4619 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4620 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4621 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4622 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4623 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4624 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4625 4626
4628 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4629 4630 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4631 """ 4632 4633 # Base data setup. 4634 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4635 4636 # Alias the spins. 4637 spin70 = return_spin(":70") 4638 spin71 = return_spin(":71") 4639 4640 # The R20 keys. 4641 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4642 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4643 4644 # Set the initial parameter values. 4645 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4646 spin70.pA = 0.9897754407 4647 spin70.dw = 5.642418428 4648 spin70.kex = 1743.666375 4649 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4650 spin71.pA = 0.9968032899 4651 spin71.dw = 4.577891393 4652 spin71.kex = 1830.044597 4653 4654 # Low precision optimisation. 4655 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4656 4657 # Printout. 4658 print("\n\nOptimised parameters:\n") 4659 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4660 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4661 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4662 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4663 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4664 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4665 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4666 4667 # Checks for residue :70. 4668 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4669 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4670 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4671 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4672 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4673 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4674 4675 # Checks for residue :71. 4676 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4677 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4678 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4679 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4680 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4681 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4682 4683 # Test the conversion to k_AB from kex and pA. 4684 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4685 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4686 4687 # Test the conversion to k_BA from kex and pA. 4688 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4689 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4690 4691
4693 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4694 4695 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4696 """ 4697 4698 # Base data setup. 4699 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4700 4701 # Alias the spins. 4702 spin70 = return_spin(":70") 4703 spin71 = return_spin(":71") 4704 4705 # The R20 keys. 4706 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4707 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4708 4709 # Set the initial parameter values. 4710 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4711 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4712 spin70.pA = 0.9884781357 4713 spin70.dw = 5.456507396 4714 spin70.kex = 1906.521189 4715 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4716 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4717 spin71.pA = 0.986709616684097 4718 spin71.dw = 2.09245158280905 4719 spin71.kex = 2438.2766211401 4720 4721 # Low precision optimisation. 4722 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4723 4724 # Printout. 4725 print("\n\nOptimised parameters:\n") 4726 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4727 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4728 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4729 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4730 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4731 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4732 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4733 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4734 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4735 4736 # Checks for residue :70. 4737 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4738 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4739 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4740 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4741 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4742 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4743 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4744 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4745 4746 # Checks for residue :71. 4747 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4748 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4749 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4750 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4751 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4752 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4753 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4754 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4755 4756 # Test the conversion to k_AB from kex and pA. 4757 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4758 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4759 4760 # Test the conversion to k_BA from kex and pA. 4761 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4762 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4763 4764
4766 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4767 4768 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4769 """ 4770 4771 # Base data setup. 4772 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4773 4774 # Alias the spins. 4775 spin70 = return_spin(":70") 4776 spin71 = return_spin(":71") 4777 4778 # The R20 keys. 4779 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4780 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4781 4782 # Set the initial parameter values. 4783 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4784 spin70.pA = 0.9 4785 spin70.dw = 6.0 4786 spin70.kex = 1500.0 4787 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4788 spin71.pA = 0.9 4789 spin71.dw = 4.0 4790 spin71.kex = 1900.0 4791 4792 # Low precision optimisation. 4793 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4794 4795 # Printout. 4796 print("\n\nOptimised parameters:\n") 4797 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4798 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4799 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4800 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4801 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4802 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4803 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4804 4805 # Checks for residue :70. 4806 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4807 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4808 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4809 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4810 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4811 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4812 4813 # Checks for residue :71. 4814 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4815 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4816 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4817 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4818 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4819 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4820 4821 # Test the conversion to k_AB from kex and pA. 4822 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4823 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4824 4825 # Test the conversion to k_BA from kex and pA. 4826 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4827 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4828 4829
4831 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4832 4833 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4834 """ 4835 4836 # Base data setup. 4837 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4838 4839 # Alias the spins. 4840 spin70 = return_spin(":70") 4841 spin71 = return_spin(":71") 4842 4843 # The R20 keys. 4844 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4845 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4846 4847 # Set the initial parameter values. 4848 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4849 spin70.pA = 0.9897519798 4850 spin70.dw = 5.644862195 4851 spin70.kex = 1723.820567 4852 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4853 spin71.pA = 0.9968032899 4854 spin71.dw = 4.577891393 4855 spin71.kex = 1830.044597 4856 4857 # Low precision optimisation. 4858 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4859 4860 # Printout. 4861 print("\n\nOptimised parameters:\n") 4862 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4863 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4864 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4865 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4866 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4867 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4868 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4869 4870 # Checks for residue :70. 4871 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4872 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4873 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4874 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4875 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4876 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4877 4878 # Checks for residue :71. 4879 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4880 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4881 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4882 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4883 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4884 4885 # Test the conversion to k_AB from kex and pA. 4886 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4887 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4888 4889 # Test the conversion to k_BA from kex and pA. 4890 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4891 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4892 4893
4895 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4896 4897 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4898 """ 4899 4900 # Base data setup. 4901 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4902 4903 # Alias the spins. 4904 spin70 = return_spin(":70") 4905 spin71 = return_spin(":71") 4906 4907 # The R20 keys. 4908 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4909 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4910 4911 # Set the initial parameter values. 4912 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4913 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4914 spin70.pA = 0.987648082613451 4915 spin70.dw = 5.30679853807572 4916 spin70.kex = 2033.25380420666 4917 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4918 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4919 spin71.pA = 0.992258541625787 4920 spin71.dw = 2.75140650899058 4921 spin71.kex = 2106.60885247431 4922 4923 # Low precision optimisation. 4924 self.interpreter.minimise.calculate() 4925 4926 # Checks for residue :70. 4927 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4928 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4929 4930
4931 - def test_hansen_cpmgfit_input(self):
4932 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4933 4934 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4935 """ 4936 4937 # Load the R2eff results file. 4938 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4939 self.interpreter.results.read(file_name) 4940 self.interpreter.deselect.spin(':4') 4941 4942 # Set up the model. 4943 self.interpreter.relax_disp.select_model('LM63') 4944 4945 # Generate the input files. 4946 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4947 4948 # What the files should contain. 4949 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4950 spin1 = [ 4951 "title :70@N\n", 4952 "fields 2 11.7432964915 18.7892743865\n", 4953 "function CPMG\n", 4954 "R2 1 10 20\n", 4955 "Rex 0 100.0 100\n", 4956 "Tau 0 10.0 100\n", 4957 "xmgr\n", 4958 "@ xaxis label \"1/tcp (1/ms)\"\n", 4959 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4960 "@ xaxis ticklabel format decimal\n", 4961 "@ yaxis ticklabel format decimal\n", 4962 "@ xaxis ticklabel char size 0.8\n", 4963 "@ yaxis ticklabel char size 0.8\n", 4964 "@ world xmin 0.0\n", 4965 "data\n", 4966 "0.133333 16.045541 0.310925 11.743296 \n", 4967 "0.266667 14.877925 0.303217 11.743296 \n", 4968 "0.400000 14.357820 0.299894 11.743296 \n", 4969 "0.533333 12.664495 0.289532 11.743296 \n", 4970 "0.666667 12.363205 0.287760 11.743296 \n", 4971 "0.800000 11.092532 0.280514 11.743296 \n", 4972 "0.933333 10.566090 0.277619 11.743296 \n", 4973 "1.066667 9.805807 0.273544 11.743296 \n", 4974 "1.200000 9.564301 0.272276 11.743296 \n", 4975 "1.333333 9.015634 0.269442 11.743296 \n", 4976 "1.466667 8.607765 0.267375 11.743296 \n", 4977 "1.600000 8.279997 0.265740 11.743296 \n", 4978 "1.733333 8.474536 0.266708 11.743296 \n", 4979 "1.866667 8.158973 0.265141 11.743296 \n", 4980 "2.000000 7.988631 0.264304 11.743296 \n", 4981 "0.133333 22.224914 0.166231 18.789274 \n", 4982 "0.266667 21.230874 0.162377 18.789274 \n", 4983 "0.400000 20.603704 0.160017 18.789274 \n", 4984 "0.533333 20.327797 0.158996 18.789274 \n", 4985 "0.666667 18.855377 0.153719 18.789274 \n", 4986 "0.800000 18.537531 0.152617 18.789274 \n", 4987 "0.933333 17.508069 0.149138 18.789274 \n", 4988 "1.066667 16.035604 0.144391 18.789274 \n", 4989 "1.200000 15.168192 0.141717 18.789274 \n", 4990 "1.333333 14.431802 0.139516 18.789274 \n", 4991 "1.466667 14.034137 0.138354 18.789274 \n", 4992 "1.600000 12.920148 0.135192 18.789274 \n", 4993 "1.733333 12.653673 0.134456 18.789274 \n", 4994 "1.866667 12.610864 0.134338 18.789274 \n", 4995 "2.000000 11.969303 0.132601 18.789274 \n" 4996 ] 4997 spin2 = [ 4998 "title :71@N\n", 4999 "fields 2 11.7432964915 18.7892743865\n", 5000 "function CPMG\n", 5001 "R2 1 10 20\n", 5002 "Rex 0 100.0 100\n", 5003 "Tau 0 10.0 100\n", 5004 "xmgr\n", 5005 "@ xaxis label \"1/tcp (1/ms)\"\n", 5006 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 5007 "@ xaxis ticklabel format decimal\n", 5008 "@ yaxis ticklabel format decimal\n", 5009 "@ xaxis ticklabel char size 0.8\n", 5010 "@ yaxis ticklabel char size 0.8\n", 5011 "@ world xmin 0.0\n", 5012 "data\n", 5013 "0.133333 7.044342 0.170035 11.743296 \n", 5014 "0.266667 6.781033 0.169228 11.743296 \n", 5015 "0.400000 6.467623 0.168279 11.743296 \n", 5016 "0.533333 6.333340 0.167876 11.743296 \n", 5017 "0.666667 6.323238 0.167846 11.743296 \n", 5018 "0.800000 6.005245 0.166902 11.743296 \n", 5019 "0.933333 5.767052 0.166203 11.743296 \n", 5020 "1.066667 5.476968 0.165361 11.743296 \n", 5021 "1.200000 5.469949 0.165341 11.743296 \n", 5022 "1.333333 5.295113 0.164838 11.743296 \n", 5023 "1.466667 5.435648 0.165242 11.743296 \n", 5024 "1.600000 5.410400 0.165169 11.743296 \n", 5025 "1.733333 5.437554 0.165247 11.743296 \n", 5026 "1.866667 5.176844 0.164501 11.743296 \n", 5027 "2.000000 5.227232 0.164644 11.743296 \n", 5028 "0.133333 11.530903 0.081928 18.789274 \n", 5029 "0.266667 10.983094 0.081041 18.789274 \n", 5030 "0.400000 10.512403 0.080294 18.789274 \n", 5031 "0.533333 9.984805 0.079473 18.789274 \n", 5032 "0.666667 9.573163 0.078845 18.789274 \n", 5033 "0.800000 9.178810 0.078253 18.789274 \n", 5034 "0.933333 8.935719 0.077893 18.789274 \n", 5035 "1.066667 8.610147 0.077416 18.789274 \n", 5036 "1.200000 8.353778 0.077045 18.789274 \n", 5037 "1.333333 8.173729 0.076787 18.789274 \n", 5038 "1.466667 8.091607 0.076670 18.789274 \n", 5039 "1.600000 7.706420 0.076126 18.789274 \n", 5040 "1.733333 7.709125 0.076129 18.789274 \n", 5041 "1.866667 7.610856 0.075992 18.789274 \n", 5042 "2.000000 7.552584 0.075911 18.789274 \n", 5043 ] 5044 5045 # Check the batch file. 5046 print("\nChecking the batch file.") 5047 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 5048 lines = file.readlines() 5049 file.close() 5050 for i in range(len(lines)): 5051 self.assertEqual(batch_file[i], lines[i]) 5052 5053 # Check spin :70@N. 5054 print("\nChecking the spin :70@N input file.") 5055 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 5056 lines = file.readlines() 5057 file.close() 5058 for i in range(len(spin1)): 5059 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5060 for i in range(len(lines)): 5061 self.assertEqual(spin1[i], lines[i]) 5062 5063 # Check spin :71@N. 5064 print("\nChecking the spin :71@N input file.") 5065 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 5066 lines = file.readlines() 5067 file.close() 5068 for i in range(len(lines)): 5069 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5070 for i in range(len(spin2)): 5071 self.assertEqual(spin2[i], lines[i])
5072 5073
5075 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 5076 5077 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5078 5079 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 5080 5081 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 5082 - pA = 0.965402506690231, 5083 - dw = 0.805197170133360, 5084 - dwH = -0.595536627771890, 5085 - kex = 569.003663067619868, 5086 - chi2 = 9.297671357952812. 5087 """ 5088 5089 # Base data setup. 5090 self.setup_korzhnev_2005_data(data_list=['DQ']) 5091 5092 # Alias the spin. 5093 spin = return_spin(":9@N") 5094 5095 # The R20 keys. 5096 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5097 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5098 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5099 5100 # Set the initial parameter values. 5101 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 5102 spin.pA = 0.965638501551899 5103 spin.dw = 2.8537583461577 5104 spin.dwH = -0.387633062766635 5105 spin.kex = 573.704033851592 5106 5107 # Low precision optimisation. 5108 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5109 5110 # Monte Carlo simulations. 5111 self.interpreter.monte_carlo.setup(number=3) 5112 self.interpreter.monte_carlo.create_data(method='back_calc') 5113 self.interpreter.monte_carlo.initial_values() 5114 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5115 self.interpreter.monte_carlo.error_analysis() 5116 5117 # Plot the dispersion curves. 5118 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5119 5120 # Save the results. 5121 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5122 5123 # Printout. 5124 print("\n\nOptimised parameters:\n") 5125 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5126 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5127 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5128 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5129 print("%-20s %20.15g" % ("pA", spin.pA)) 5130 print("%-20s %20.15g" % ("dw", spin.dw)) 5131 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5132 print("%-20s %20.15g" % ("kex", spin.kex)) 5133 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5134 5135 # Checks for residue :9. 5136 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5137 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5138 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5139 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5140 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5141 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5142 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5143 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5144 5145
5147 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5148 5149 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5150 5151 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5152 5153 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5154 - pA = 0.930027999814003, 5155 - dw = 4.338620619954370, 5156 - dwH = -0.274250775560818, 5157 - kex = 344.613362916544475, 5158 - chi2 = 10.367733168217050. 5159 """ 5160 5161 # Base data setup. 5162 self.setup_korzhnev_2005_data(data_list=['MQ']) 5163 5164 # Alias the spin. 5165 spin = return_spin(":9@N") 5166 5167 # The R20 keys. 5168 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5169 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5170 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5171 5172 # Set the initial parameter values. 5173 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5174 spin.pA = 0.930083249288083 5175 spin.dw = 4.33890689462363 5176 spin.dwH = -0.274316585638047 5177 spin.kex = 344.329651956132 5178 5179 # Low precision optimisation. 5180 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5181 5182 # Monte Carlo simulations. 5183 self.interpreter.monte_carlo.setup(number=3) 5184 self.interpreter.monte_carlo.create_data(method='back_calc') 5185 self.interpreter.monte_carlo.initial_values() 5186 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5187 self.interpreter.monte_carlo.error_analysis() 5188 5189 # Plot the dispersion curves. 5190 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5191 5192 # Save the results. 5193 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5194 5195 # Printout. 5196 print("\n\nOptimised parameters:\n") 5197 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5198 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5199 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5200 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5201 print("%-20s %20.15g" % ("pA", spin.pA)) 5202 print("%-20s %20.15g" % ("dw", spin.dw)) 5203 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5204 print("%-20s %20.15g" % ("kex", spin.kex)) 5205 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5206 5207 # Checks for residue :9. 5208 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5209 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5210 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5211 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5212 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5213 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5214 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5215 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5216 5217
5219 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5220 5221 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5222 5223 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5224 5225 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5226 - pA = 0.950003458294991, 5227 - dw = 4.358402855315123, 5228 - kex = 429.906473361926999, 5229 - chi2 = 17.393331915567252. 5230 """ 5231 5232 # Base data setup. 5233 self.setup_korzhnev_2005_data(data_list=['SQ']) 5234 5235 # Alias the spin. 5236 spin = return_spin(":9@N") 5237 5238 # The R20 keys. 5239 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5240 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5241 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5242 5243 # Set the initial parameter values. 5244 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5245 spin.pA = 0.950310172115387 5246 spin.dw = 4.356737157889636 5247 spin.kex = 433.176323890829849 5248 5249 # Low precision optimisation. 5250 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5251 5252 # Monte Carlo simulations. 5253 self.interpreter.monte_carlo.setup(number=3) 5254 self.interpreter.monte_carlo.create_data(method='back_calc') 5255 self.interpreter.monte_carlo.initial_values() 5256 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5257 self.interpreter.monte_carlo.error_analysis() 5258 5259 # Plot the dispersion curves. 5260 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5261 5262 # Save the results. 5263 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5264 5265 # Printout. 5266 print("\n\nOptimised parameters:\n") 5267 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5268 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5269 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5270 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5271 print("%-20s %20.15g" % ("pA", spin.pA)) 5272 print("%-20s %20.15g" % ("dw", spin.dw)) 5273 print("%-20s %20.15g" % ("kex", spin.kex)) 5274 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5275 5276 # Checks for residue :9. 5277 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5278 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5279 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5280 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5281 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5282 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5283 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5284 5285
5287 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5288 5289 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5290 5291 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5292 5293 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5294 - pA = 0.942452612380140, 5295 - dw = 0.858972784230892, 5296 - dwH = 0.087155962730608, 5297 - kex = 373.219151384798920, 5298 - chi2 = 23.863208106025152. 5299 """ 5300 5301 # Base data setup. 5302 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5303 5304 # Alias the spin. 5305 spin = return_spin(":9@N") 5306 5307 # The R20 keys. 5308 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5309 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5310 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5311 5312 # Set the initial parameter values. 5313 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5314 spin.pA = 0.942457332074014 5315 spin.dw = 0.850592422908884 5316 spin.dwH = 0.0881272284455416 5317 spin.kex = 372.745483351305 5318 5319 # Low precision optimisation. 5320 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5321 5322 # Monte Carlo simulations. 5323 self.interpreter.monte_carlo.setup(number=3) 5324 self.interpreter.monte_carlo.create_data(method='back_calc') 5325 self.interpreter.monte_carlo.initial_values() 5326 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5327 self.interpreter.monte_carlo.error_analysis() 5328 5329 # Plot the dispersion curves. 5330 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5331 5332 # Save the results. 5333 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5334 5335 # Printout. 5336 print("\n\nOptimised parameters:\n") 5337 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5338 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5339 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5340 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5341 print("%-20s %20.15g" % ("pA", spin.pA)) 5342 print("%-20s %20.15g" % ("dw", spin.dw)) 5343 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5344 print("%-20s %20.15g" % ("kex", spin.kex)) 5345 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5346 5347 # Checks for residue :9. 5348 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5349 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5350 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5351 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5352 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5353 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5354 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5355 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5356 5357
5359 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5360 5361 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5362 5363 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5364 5365 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5366 - pA = 0.936911090448340, 5367 - dw = 4.325314846914845, 5368 - dwH = -0.213870168665628, 5369 - kex = 487.361914835074117, 5370 - chi2 = 14.870371897291138. 5371 """ 5372 5373 # Base data setup. 5374 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5375 5376 # Alias the spin. 5377 spin = return_spin(":9@N") 5378 5379 # The R20 keys. 5380 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5381 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5382 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5383 5384 # Set the initial parameter values. 5385 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5386 spin.pA = 0.936884348941701 5387 spin.dw = 4.326454531583964 5388 spin.dwH = -0.214026093221782 5389 spin.kex = 487.043592705469223 5390 5391 # Low precision optimisation. 5392 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5393 5394 # Monte Carlo simulations. 5395 self.interpreter.monte_carlo.setup(number=3) 5396 self.interpreter.monte_carlo.create_data(method='back_calc') 5397 self.interpreter.monte_carlo.initial_values() 5398 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5399 self.interpreter.monte_carlo.error_analysis() 5400 5401 # Plot the dispersion curves. 5402 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5403 5404 # Save the results. 5405 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5406 5407 # Printout. 5408 print("\n\nOptimised parameters:\n") 5409 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5410 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5411 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5412 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5413 print("%-20s %20.15g" % ("pA", spin.pA)) 5414 print("%-20s %20.15g" % ("dw", spin.dw)) 5415 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5416 print("%-20s %20.15g" % ("kex", spin.kex)) 5417 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5418 5419 # Checks for residue :9. 5420 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5421 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5422 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5423 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5424 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5425 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5426 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5427 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5428 5429
5431 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5432 5433 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5434 5435 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5436 5437 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5438 - pA = 0.946949480545876, 5439 - dwH = -0.265279672133308, 5440 - kex = 406.548178869750700, 5441 - chi2 = 50.400680290545026. 5442 """ 5443 5444 # Base data setup. 5445 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5446 5447 # Alias the spin. 5448 spin = return_spin(":9@N") 5449 5450 # The R20 keys. 5451 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5452 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5453 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5454 5455 # Set the initial parameter values. 5456 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5457 spin.pA = 0.946990967372467 5458 spin.dwH = -0.265308128403529 5459 spin.kex = 406.843250675648 5460 5461 # Low precision optimisation. 5462 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5463 5464 # Monte Carlo simulations. 5465 self.interpreter.monte_carlo.setup(number=3) 5466 self.interpreter.monte_carlo.create_data(method='back_calc') 5467 self.interpreter.monte_carlo.initial_values() 5468 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5469 self.interpreter.monte_carlo.error_analysis() 5470 5471 # Plot the dispersion curves. 5472 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5473 5474 # Save the results. 5475 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5476 5477 # Printout. 5478 print("\n\nOptimised parameters:\n") 5479 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5480 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5481 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5482 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5483 print("%-20s %20.15g" % ("pA", spin.pA)) 5484 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5485 print("%-20s %20.15g" % ("kex", spin.kex)) 5486 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5487 5488 # Checks for residue :9. 5489 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5490 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5491 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5492 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5493 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5494 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5495 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5496 5497
5499 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5500 5501 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5502 5503 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5504 5505 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5506 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5507 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5508 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5509 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5510 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5511 - pA = 0.943125351763911, 5512 - dw = 4.421827493809807, 5513 - dwH = -0.272637034755752, 5514 - kex = 360.609744568697238, 5515 - chi2 = 162.589570340050813. 5516 """ 5517 5518 # Base data setup. 5519 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5520 5521 # Alias the spin. 5522 spin = return_spin(":9@N") 5523 5524 # The R20 keys. 5525 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5526 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5527 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5528 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5529 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5530 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5531 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5532 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5533 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5534 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5535 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5536 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5537 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5538 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5539 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5540 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5541 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5542 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5543 5544 # Set the initial parameter values. 5545 spin.r2 = { 5546 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5547 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5548 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5549 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5550 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5551 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5552 } 5553 spin.pA = 0.943129019477673 5554 spin.dw = 4.42209952545181 5555 spin.dwH = -0.27258970590969 5556 spin.kex = 360.516132791038 5557 5558 # Low precision optimisation. 5559 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5560 5561 # Monte Carlo simulations. 5562 self.interpreter.monte_carlo.setup(number=3) 5563 self.interpreter.monte_carlo.create_data(method='back_calc') 5564 self.interpreter.monte_carlo.initial_values() 5565 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5566 self.interpreter.monte_carlo.error_analysis() 5567 5568 # Plot the dispersion curves. 5569 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5570 5571 # Save the results. 5572 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5573 5574 # Printout. 5575 print("\n\nOptimised parameters:\n") 5576 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5577 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5578 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5579 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5580 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5581 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5582 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5583 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5584 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5585 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5586 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5587 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5588 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5589 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5590 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5591 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5592 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5593 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5594 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5595 print("%-20s %20.15g" % ("pA", spin.pA)) 5596 print("%-20s %20.15g" % ("dw", spin.dw)) 5597 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5598 print("%-20s %20.15g" % ("kex", spin.kex)) 5599 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5600 5601 # Checks for residue :9. 5602 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5603 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5604 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5605 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5606 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5607 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5608 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5609 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5610 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5611 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5612 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5613 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5614 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5615 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5616 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5617 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5618 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5619 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5620 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5621 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5622 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5623 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5624 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5625 5626
5628 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5629 5630 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5631 5632 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5633 5634 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5635 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5636 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5637 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5638 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5639 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5640 - pA = 0.943125351763911, 5641 - dw = 4.421827493809807, 5642 - dwH = -0.272637034755752, 5643 - kex = 360.609744568697238, 5644 - chi2 = 162.589570340050813. 5645 """ 5646 5647 # Base data setup. 5648 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5649 5650 # Alias the spin. 5651 spin = return_spin(":9@N") 5652 5653 # The R20 keys. 5654 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5655 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5656 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5657 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5658 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5659 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5660 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5661 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5662 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5663 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5664 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5665 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5666 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5667 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5668 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5669 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5670 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5671 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5672 5673 # Set the initial parameter values. 5674 spin.r2 = { 5675 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5676 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5677 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5678 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5679 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5680 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5681 } 5682 spin.pA = 0.943129019477673 5683 spin.dw = 4.42209952545181 5684 spin.dwH = -0.27258970590969 5685 spin.kex = 360.516132791038 5686 5687 # Calc the chi2 values at these parameters. 5688 self.interpreter.minimise.calculate(verbosity=1) 5689 5690 # Printout. 5691 print("\n\nOptimised parameters:\n") 5692 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5693 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5694 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5695 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5696 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5697 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5698 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5699 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5700 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5701 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5702 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5703 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5704 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5705 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5706 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5707 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5708 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5709 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5710 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5711 print("%-20s %20.15g" % ("pA", spin.pA)) 5712 print("%-20s %20.15g" % ("dw", spin.dw)) 5713 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5714 print("%-20s %20.15g" % ("kex", spin.kex)) 5715 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5716 5717 # Checks for residue :9. 5718 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5719 5720
5722 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5723 5724 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5725 5726 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5727 5728 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5729 - 0.483 0.89623903 2.4503699912708878 5730 - 0.545 1.1694838 5731 - 0.545 1.1761503 5732 - 0.622 1.294 5733 - 0.669 1.5176493 5734 - 0.722 1.6238791 5735 - 0.813 1.9395758 5736 - 1.011 2.3558415 10.547000429321157 5737 """ 5738 5739 # Base data setup. 5740 model = 'TSMFK01' 5741 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5742 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5743 5744 # Alias the spins. 5745 res61L = cdp.mol[0].res[0].spin[0] 5746 5747 # The R20 keys. 5748 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5749 5750 # Set the initial parameter values. 5751 res61L.r2a = {r20_key1: 8.0} 5752 res61L.dw = 6.5 5753 res61L.k_AB = 2.5 5754 5755 # Low precision optimisation. 5756 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5757 5758 # Start testing all possible combinations of graphs. 5759 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5760 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5761 interpolate_types = [INTERPOLATE_DISP] 5762 5763 # Write to temp folder. 5764 result_dir_name = ds.tmpdir 5765 result_folders = [model] 5766 spin_id = ":61@N" 5767 5768 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5769 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5770 5771 for result_folder in result_folders: 5772 for y_axis in y_axis_types: 5773 for x_axis in x_axis_types: 5774 for interpolate in interpolate_types: 5775 # Determine file name: 5776 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5777 5778 # Make the file name. 5779 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5780 5781 # Write the curves. 5782 dir = result_dir_name+sep+result_folder 5783 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5784 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5785 5786 # Get the file path. 5787 file_path = get_file_path(file_name, dir) 5788 5789 # Test the plot file exists. 5790 print("Testing file access to graph: %s"%file_path) 5791 self.assert_(access(file_path, F_OK)) 5792 5793 # Now open, and compare content, line by line. 5794 file_prod = open(file_path) 5795 lines_prod = file_prod.readlines() 5796 file_prod.close() 5797 5798 # Define file to compare against. 5799 dir_comp = data_path+sep+result_folder 5800 file_path_comp = get_file_path(file_name, dir_comp) 5801 file_comp = open(file_path_comp) 5802 lines_comp = file_comp.readlines() 5803 file_comp.close() 5804 5805 ## Assert number of lines is equal. 5806 self.assertEqual(len(lines_prod), len(lines_comp)) 5807 for j in range(len(lines_prod)): 5808 # Make the string test 5809 first_char = lines_prod[j][0] 5810 if first_char in ["@", "&"]: 5811 self.assertEqual(lines_prod[j], lines_comp[j]) 5812 else: 5813 # Split string in x, y, error. 5814 # The error would change per run. 5815 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5816 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5817 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5818 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5819 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5820 5821
5823 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5824 5825 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5826 """ 5827 5828 # Base data setup. 5829 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5830 5831 # Alias the spins. 5832 res61L = cdp.mol[0].res[0].spin[0] 5833 5834 # The R20 keys. 5835 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5836 5837 # Set the initial parameter values. 5838 res61L.r2 = {r20_key1: 8.0} 5839 res61L.pA = 0.9 5840 res61L.dw = 6.0 5841 res61L.kex = 600.0 5842 5843 # Low precision optimisation. 5844 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5845 5846 # Printout. 5847 print("\n\nOptimised parameters:\n") 5848 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5849 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5850 print("%-20s %20.15g" % ("pA", res61L.pA)) 5851 print("%-20s %20.15g" % ("dw", res61L.dw)) 5852 print("%-20s %20.15g" % ("kex", res61L.kex)) 5853 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5854 5855 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5856 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5857 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5858 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5859 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5860 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5861 5862 # Test the conversion to k_AB from kex and pA. 5863 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5864 5865 # Test the conversion to k_BA from kex and pA. 5866 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5867 5868
5870 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5871 5872 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5873 """ 5874 5875 # Base data setup. 5876 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5877 5878 # Alias the spins. 5879 res61L = cdp.mol[0].res[0].spin[0] 5880 5881 # The R20 keys. 5882 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5883 5884 # Set the initial parameter values. 5885 res61L.r2a = {r20_key1: 8.0} 5886 res61L.r2b = {r20_key1: 105.0} 5887 res61L.pA = 0.9 5888 res61L.dw = 6.0 5889 res61L.kex = 500.0 5890 5891 # Low precision optimisation. 5892 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5893 5894 # Printout. 5895 print("\n\nOptimised parameters:\n") 5896 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5897 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5898 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5899 print("%-20s %20.15g" % ("pA", res61L.pA)) 5900 print("%-20s %20.15g" % ("dw", res61L.dw)) 5901 print("%-20s %20.15g" % ("kex", res61L.kex)) 5902 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5903 5904 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5905 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5906 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5907 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5908 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5909 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5910 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5911 5912
5914 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5915 5916 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5917 5918 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5919 5920 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5921 - 0.483 0.89623903 2.4503699912708878 5922 - 0.545 1.1694838 5923 - 0.545 1.1761503 5924 - 0.622 1.294 5925 - 0.669 1.5176493 5926 - 0.722 1.6238791 5927 - 0.813 1.9395758 5928 - 1.011 2.3558415 10.547000429321157 5929 """ 5930 5931 # Base data setup. 5932 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5933 5934 # Alias the spins. 5935 res61L = cdp.mol[0].res[0].spin[0] 5936 5937 # The R20 keys. 5938 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5939 5940 # Set the initial parameter values. 5941 res61L.r2a = {r20_key1: 8.0} 5942 res61L.dw = 6.5 5943 res61L.k_AB = 2.5 5944 5945 # Low precision optimisation. 5946 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5947 5948 # Printout. 5949 print("\n\nOptimised parameters:\n") 5950 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5951 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5952 print("%-20s %20.15g" % ("dw", res61L.dw)) 5953 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5954 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5955 5956 # Checks for residue :61. Reference values from paper 5957 5958 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5959 5960
5962 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5963 5964 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5965 5966 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5967 5968 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5969 5970 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5971 - k_AB = 11.3 +/- 0.7 s^-1, 5972 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5973 - R2 = 8.0 +/- 0.5 s^-1. 5974 5975 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5976 - k_AB = 10.55 +/- 0.08 s^-1, 5977 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5978 - R2 = 8.4 +/- 0.3 s^-1. 5979 5980 Conversion of paper results to relax results is performed by: 5981 5982 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5983 5984 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5985 5986 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5987 - 0.483 0.89623903 2.4503699912708878 5988 - 0.545 1.1694838 5989 - 0.545 1.1761503 5990 - 0.622 1.294 5991 - 0.669 1.5176493 5992 - 0.722 1.6238791 5993 - 0.813 1.9395758 5994 - 1.011 2.3558415 10.547000429321157 5995 """ 5996 5997 # Base data setup. 5998 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5999 6000 # Alias the spins. 6001 res61L = cdp.mol[0].res[0].spin[0] 6002 6003 # The R20 keys. 6004 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 6005 6006 # Set the initial parameter values. 6007 res61L.r2a = {r20_key1: 8.0} 6008 res61L.dw = 6.5 6009 res61L.k_AB = 11.0 6010 6011 # Low precision optimisation. 6012 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6013 6014 # Printout. 6015 print("\n\nOptimised parameters:\n") 6016 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 6017 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 6018 print("%-20s %20.15g" % ("dw", res61L.dw)) 6019 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 6020 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 6021 6022 # Checks for residue :61. Reference values from paper 6023 6024 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 6025 self.assertAlmostEqual(res61L.dw, 6.41, 0) 6026 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
6027 6028
6029 - def test_lm63_3site_synthetic(self):
6030 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 6031 6032 # The path to the data files. 6033 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 6034 6035 # Load the state file. 6036 self.interpreter.reset() 6037 self.interpreter.state.load(data_path+sep+'r2eff_values') 6038 6039 # A new data pipe. 6040 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 6041 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 6042 6043 # Set up the model data. 6044 self.interpreter.relax_disp.select_model(model='LM63 3-site') 6045 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 6046 self.interpreter.spin.isotope('15N') 6047 6048 # Alias the spins. 6049 spin1 = return_spin(":1") 6050 spin2 = return_spin(":2") 6051 6052 # The R20 keys. 6053 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 6054 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 6055 6056 # Manually set the parameter values. 6057 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 6058 spin1.phi_ex_B = 0.1 6059 spin1.phi_ex_C = 0.5 6060 spin1.kB = 1500.0 6061 spin1.kC = 2500.0 6062 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 6063 spin2.phi_ex_B = 0.1 6064 spin2.phi_ex_C = 0.5 6065 spin2.kB = 1500.0 6066 spin2.kC = 2500.0 6067 6068 # Low precision optimisation. 6069 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6070 6071 # Monte Carlo simulations. 6072 self.interpreter.monte_carlo.setup(number=3) 6073 self.interpreter.monte_carlo.create_data(method='back_calc') 6074 self.interpreter.monte_carlo.initial_values() 6075 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 6076 self.interpreter.monte_carlo.error_analysis() 6077 6078 # Save the results. 6079 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 6080 6081 # The model checks. 6082 print("\n\nOptimised parameters:\n") 6083 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 6084 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 6085 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 6086 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 6087 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 6088 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 6089 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 6090 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 6091 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 6092 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 6093 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6094 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6095 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6096 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6097 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 6098 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 6099 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 6100 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6101 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6102 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6103 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6104 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
6105 6106
6107 - def test_m61_data_to_m61(self):
6108 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 6109 6110 # Fixed time variable. 6111 ds.fixed = True 6112 6113 # Execute the script. 6114 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6115 6116 # The original parameters. 6117 i0 = [100000.0, 20000.0] 6118 r1rho_prime = [2.25, 24.0] 6119 pA = 0.7 6120 kex = 1000.0 6121 delta_omega = [1.0, 2.0] 6122 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6123 phi_ex = [] 6124 for i in range(2): 6125 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6126 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6127 6128 # Switch to the 'R2eff' model data pipe, then check for each spin. 6129 self.interpreter.pipe.switch('R2eff - relax_disp') 6130 spin_index = 0 6131 for spin, spin_id in spin_loop(return_id=True): 6132 # Printout. 6133 print("\nSpin %s." % spin_id) 6134 6135 # Check the fitted parameters. 6136 for i in range(len(keys)): 6137 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6138 6139 # Increment the spin index. 6140 spin_index += 1 6141 6142 # The R20 keys. 6143 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6144 6145 # Switch to the 'M61' model data pipe, then check for each spin. 6146 self.interpreter.pipe.switch('M61 - relax_disp') 6147 spin_index = 0 6148 for spin, spin_id in spin_loop(return_id=True): 6149 # Printout. 6150 print("\nSpin %s." % spin_id) 6151 6152 # Check the fitted parameters. 6153 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6154 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6155 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6156 6157 # Increment the spin index. 6158 spin_index += 1
6159 6160
6161 - def test_m61_exp_data_to_m61(self):
6162 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6163 6164 # Fixed time variable. 6165 ds.fixed = False 6166 6167 # Single spin optimisation. 6168 ds.single = True 6169 6170 # Execute the script. 6171 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6172 6173 # The original parameters. 6174 i0 = [100000.0, 20000.0] 6175 r1rho_prime = [2.25, 24.0] 6176 pA = 0.7 6177 kex = 1000.0 6178 delta_omega = [1.0, 2.0] 6179 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6180 phi_ex = [] 6181 for i in range(2): 6182 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6183 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6184 6185 # Switch to the 'R2eff' model data pipe, then check for each spin. 6186 self.interpreter.pipe.switch('R2eff - relax_disp') 6187 spin_index = 0 6188 for spin, spin_id in spin_loop(return_id=True): 6189 # Printout. 6190 print("\nSpin %s." % spin_id) 6191 6192 # Check the fitted parameters. 6193 for i in range(len(keys)): 6194 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6195 6196 # Increment the spin index. 6197 spin_index += 1 6198 6199 # The R20 keys. 6200 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6201 6202 # Switch to the 'M61' model data pipe, then check for each spin. 6203 self.interpreter.pipe.switch('M61 - relax_disp') 6204 spin_index = 0 6205 for spin, spin_id in spin_loop(return_id=True): 6206 # Printout. 6207 print("\nSpin %s." % spin_id) 6208 6209 # Check the fitted parameters. 6210 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6211 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6212 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6213 6214 # Increment the spin index. 6215 spin_index += 1
6216 6217
6218 - def test_m61b_data_to_m61b(self):
6219 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6220 6221 # Execute the script. 6222 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 6223 6224 # The original parameters. 6225 i0 = [100000.0, 20000.0] 6226 r1rho_prime = [10.0, 24.0] 6227 pA = 0.95 6228 kex = 2000.0 6229 delta_omega = [1.0, 2.0] 6230 6231 # The R20 keys. 6232 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6233 6234 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6235 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6236 spin_index = 0 6237 for spin, spin_id in spin_loop(return_id=True): 6238 # Printout. 6239 print("\nSpin %s." % spin_id) 6240 6241 # Check the fitted parameters. 6242 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6243 self.assertAlmostEqual(spin.pA, pA, 2) 6244 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6245 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6246 6247 # Increment the spin index. 6248 spin_index += 1
6249 6250
6252 """Test that all models which can nest, have all their parameters converted.""" 6253 6254 # Set the experiment type. 6255 cdp.exp_type_list = EXP_TYPE_LIST 6256 6257 # Get info for all models. 6258 all_models_info = models_info(models=MODEL_LIST_FULL) 6259 6260 # Loop over all models. 6261 print("Printing the listed of nested models for each model.") 6262 print("#########################################") 6263 for model_info in all_models_info: 6264 print("%s"%model_info.model), 6265 print("<-"), 6266 nest_list = model_info.nest_list 6267 if nest_list == None: 6268 nest_list = ["None"] 6269 print(', '.join(map(str, nest_list))) 6270 6271 # Skip if there is no model to nest from. 6272 if nest_list == ["None"]: 6273 continue 6274 6275 # Assign params to variable. 6276 model_params = model_info.params 6277 6278 # Now loop over the nested models. 6279 for nested_model in nest_list: 6280 # Get the params for the nested model. 6281 nested_model_params = MODEL_PARAMS[nested_model] 6282 6283 # Get the dictionary of parameter conversion. 6284 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6285 6286 # Test the number of elements in the dictionary. 6287 self.assertEqual(len(par_dic), len(model_params)) 6288 6289 # Loop over dictionary. 6290 for param in par_dic: 6291 if param != par_dic[param]: 6292 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6293 self.assertNotEqual(par_dic[param], None)
6294 6295
6296 - def test_ns_mmq_3site(self):
6297 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6298 6299 # Execute the script. 6300 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6301 6302 # Check the chi-squared value. 6303 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6304 6305
6306 - def test_ns_mmq_3site_linear(self):
6307 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6308 6309 # Execute the script. 6310 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6311 6312 # Check the chi-squared value. 6313 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6314 6315
6316 - def test_ns_r1rho_3site(self):
6317 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6318 6319 # Execute the script. 6320 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6321 6322 # Check the chi-squared value. 6323 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6324 6325
6326 - def test_ns_r1rho_3site_linear(self):
6327 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6328 6329 # Execute the script. 6330 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6331 6332 # Check the chi-squared value. 6333 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6334 6335
6336 - def test_paul_schanda_nov_2015(self):
6337 """This test truncated private data which was provided by Paul Schanda. This systemtest uncovers some unfortunate problems when 6338 running an analysis and reading points by the R2eff method. 6339 """ 6340 6341 # Assign 6342 outdir = ds.tmpdir 6343 6344 # Execute the setup and creation of files. 6345 self.setup_paul_schanda_nov_2015(outdir=outdir) 6346 6347 # Minimum: Just read the sequence data, but this misses a lot of information. 6348 self.interpreter.sequence.read(file='residues.txt', res_num_col=1, dir=outdir) 6349 6350 # Open the settings file. 6351 set_file = open(outdir+sep+"exp_settings.txt") 6352 set_file_lines = set_file.readlines() 6353 6354 # Now load the data. 6355 for line in set_file_lines: 6356 if "#" in line[0]: 6357 continue 6358 6359 # Get data 6360 field, RF_field_strength_kHz, f_name = line.split() 6361 6362 # Assign data 6363 spec_id = f_name 6364 self.interpreter.relax_disp.exp_type(spectrum_id=spec_id, exp_type='R1rho') 6365 6366 # Set the spectrometer frequency 6367 self.interpreter.spectrometer.frequency(id=spec_id, frq=float(field), units='MHz') 6368 6369 # Is in kHz, som convert to Hz 6370 disp_frq = float(RF_field_strength_kHz)*1000 6371 6372 # Set The spin-lock field strength, nu1, in Hz 6373 self.interpreter.relax_disp.spin_lock_field(spectrum_id=spec_id, field=disp_frq) 6374 6375 # Read the R2eff data 6376 self.interpreter.relax_disp.r2eff_read(id=spec_id, file=f_name, dir=None, disp_frq=disp_frq, res_num_col=1, data_col=2, error_col=3) 6377 6378 # Is this necessary? The time, in seconds, of the relaxation period. 6379 #self.interpreter.relax_disp.relax_time(spectrum_id=spec_id, time=time_sl) 6380 6381 6382 # Check that the number of R2eff points is correct after dropping 1 datapoint for spin 51. 6383 r2eff_points = [] 6384 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6385 # Loop over the R2eff points 6386 for key in cur_spin.r2eff: 6387 value = cur_spin.r2eff[key] 6388 err = cur_spin.r2eff_err[key] 6389 r2eff_points.append(value) 6390 6391 # Test that values and errors are not nan. 6392 self.assert_(not isnan(value)) 6393 self.assert_(not isnan(err)) 6394 6395 6396 # Test the number of r2eff points. One is subtracted, due to one of the error values are "nan" in spin 51. 6397 self.assertEqual(len(r2eff_points), 2*(10+19)-1) 6398 6399 # Test stored value in the pipe. 6400 self.assertEqual(len(cdp.mol), 1) 6401 self.assertEqual(cdp.mol[0].name, None) 6402 self.assertEqual(len(cdp.mol[0].res), 2) 6403 6404 self.assertEqual(cdp.spectrometer_frq_count, 2) 6405 print cdp.spectrometer_frq_list 6406 self.assertEqual(cdp.spectrometer_frq_list, [600000000.0, 950000000.0]) 6407 self.assertEqual(cdp.exp_type_list, ['R1rho']) 6408 6409 # Test the number of frequencies. 6410 count_600 = 0 6411 count_950 = 0 6412 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 6413 if frq == cdp.spectrometer_frq_list[0]: 6414 count_600 += 1 6415 elif frq == cdp.spectrometer_frq_list[1]: 6416 count_950 += 1 6417 6418 # Assert the number of points 6419 self.assertEqual(count_600, 10) 6420 self.assertEqual(count_950, 19) 6421 6422 # Name the isotope for field strength scaling. 6423 self.interpreter.spin.isotope(isotope='15N') 6424 6425 # Now test that the plotting can be performed of just the raw data. 6426 self.assertRaises(RelaxError, self.interpreter.relax_disp.plot_disp_curves, dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True) 6427 self.interpreter.relax_disp.select_model(model=MODEL_R2EFF) 6428 self.interpreter.relax_disp.plot_disp_curves(dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True) 6429 6430 6431 # Number of grid search increments. If set to None, then the grid search will be turned off and the default parameter values will be used instead. 6432 #GRID_INC = None 6433 GRID_INC = 21 6434 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6435 MC_NUM = 3 6436 # Model selection technique. 6437 MODSEL = 'AIC' 6438 # Which models to analyse ? 6439 MODELS = [MODEL_NOREX, MODEL_M61] 6440 # Fit, instead of read. Off for On-resonance. 6441 r1_fit = False 6442 # Set the initial guess from the minimum R2eff point 6443 set_grid_r20=True 6444 6445 # Execute the auto-analysis (fast). 6446 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6447 OPT_FUNC_TOL = 1e-1 6448 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6449 OPT_MAX_ITERATIONS = 1000 6450 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6451 6452 # Go 6453 relax_disp.Relax_disp(pipe_name="relax_disp", pipe_bundle="relax_disp", results_dir=outdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit) 6454 6455 # Now simulate that all spins are first deselected, and then selected. 6456 self.interpreter.deselect.all() 6457 sel_ids = [ 6458 ":12", 6459 ":51", 6460 ] 6461 for sel_spin in sel_ids: 6462 print("Selecting spin %s"%sel_spin) 6463 self.interpreter.select.spin(spin_id=sel_spin, change_all=False) 6464 6465 # Inspect which residues should be analysed together for a clustered/global fit. 6466 cluster_ids = sel_ids 6467 6468 # Cluster spins 6469 for curspin in cluster_ids: 6470 print("Adding spin %s to cluster"%curspin) 6471 self.interpreter.relax_disp.cluster('model_cluster', curspin) 6472 6473 # Show the pipe 6474 print("\nPrinting all the available pipes.") 6475 self.interpreter.pipe.display() 6476 6477 # Get the selected models 6478 print("\nChecking which model is stored per spin.") 6479 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6480 print("For spin_id '%s the model is '%s''"%(spin_id, curspin.model)) 6481 6482 # Copy pipe and switch to it. 6483 self.interpreter.pipe.copy(pipe_from="final - relax_disp", pipe_to="relax_disp_cluster", bundle_to="relax_disp_cluster") 6484 self.interpreter.pipe.switch(pipe_name="relax_disp_cluster") 6485 self.interpreter.pipe.display() 6486 6487 # Go again with clustered spins. 6488 relax_disp.Relax_disp(pipe_name="relax_disp_cluster", pipe_bundle="relax_disp_cluster", results_dir=outdir+sep+"cluster", models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit) 6489 6490 # Get the clustered fitted values 6491 print("\nChecking which value is stored per spin.") 6492 kex = None 6493 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6494 if kex == None: 6495 kex = curspin.kex 6496 self.assertEqual(curspin.kex, kex) 6497 print("For spin_id %s the kex is %.3f"%(spin_id, kex))
6498 6499
6500 - def test_repeat_cpmg(self):
6501 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6502 6503 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6504 """ 6505 6506 # Reset. 6507 self.interpreter.reset() 6508 6509 # Define base path to files. 6510 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6511 6512 # Setup dictionary with settings. 6513 sdic = {} 6514 6515 # Spectrometer frqs in list. 6516 sfrq_1 = 499.86214 6517 sfrq_2 = 599.8908587 6518 sfrqs = [sfrq_1, sfrq_2] 6519 6520 # Store in dictionary. 6521 sdic['sfrqs'] = sfrqs 6522 6523 # Store unit for frq. 6524 sdic['sfrq_unit'] = 'MHz' 6525 6526 # Store exp_type 6527 sdic['exp_type'] = 'SQ CPMG' 6528 6529 # Store spin isotope 6530 sdic['isotope'] = '15N' 6531 6532 # How intensity was measured. 6533 sdic['int_method'] = 'height' 6534 6535 # Define the time for result directory. 6536 sdic['time'] = '2014_09' 6537 6538 # Initialize frq dics. 6539 for frq in sfrqs: 6540 key = DIC_KEY_FORMAT % (frq) 6541 sdic[key] = {} 6542 6543 # Set keys. 6544 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6545 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6546 6547 # Store time T2. 6548 sdic[e_1]['time_T2'] = 0.04 6549 sdic[e_2]['time_T2'] = 0.06 6550 6551 # Set ncyc. 6552 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6553 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6554 6555 # Calculate the cpmg_frq and store. 6556 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6557 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6558 6559 # Define peak lists. 6560 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6561 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6562 sdic[e_1]['peaks_folder'] = peaks_folder_1 6563 sdic[e_2]['peaks_folder'] = peaks_folder_2 6564 6565 # Define folder to all rmsd files. 6566 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6567 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6568 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6569 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6570 6571 # Define temporary folder. 6572 sdic['results_dir'] = self.tmpdir 6573 6574 # Setup class with data. 6575 RDR = Relax_disp_rep(sdic) 6576 6577 # Setup base information. 6578 RDR.set_base_cpmg(method='FT', glob_ini=128) 6579 6580 methods = ['FT', 'MDD'] 6581 #methods = ['FT'] 6582 6583 # Set the intensity. 6584 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6585 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6586 6587 # Try plot some intensity correlations. 6588 if True: 6589 selection = None 6590 6591 # Now make a spin selection. 6592 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6593 6594 # For mdd 6595 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6596 6597 # Plot correlation of intensity 6598 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6599 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6600 corr_data = [fig1, fig2] 6601 6602 write_stats = True 6603 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6604 6605 # Open stat file. 6606 if write_stats: 6607 for i, corr_data_i in enumerate(corr_data): 6608 data, methods, glob_inis = corr_data[i] 6609 data_x, data_y = data 6610 method_x, method_y = methods 6611 glob_ini_x, glob_ini_y = glob_inis 6612 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6613 np = len(x) 6614 6615 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6616 6617 if selection == None: 6618 file_name = file_name_ini + '_all.txt' 6619 else: 6620 file_name = file_name_ini + '_sel.txt' 6621 path = RDR.results_dir 6622 data = extract_data(file=file_name, dir=path) 6623 6624 # Loop over the lines. 6625 for i, data_i in enumerate(data): 6626 print(i, data_i) 6627 6628 6629 # Try plot some intensity statistics. 6630 if True: 6631 # Collect r2eff values. 6632 selections = [None, ':2,3'] 6633 for selection in selections: 6634 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6635 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6636 6637 # Get R2eff stats. 6638 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6639 6640 ## Plot R2eff stats 6641 write_stats = True 6642 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6643 6644 # Open stat file. 6645 if write_stats: 6646 if selection == None: 6647 file_name = 'int_stat_all.txt' 6648 else: 6649 file_name = 'int_stat_sel.txt' 6650 path = RDR.results_dir 6651 data = extract_data(file=file_name, dir=path) 6652 6653 # Loop over the lines. 6654 for i, data_i in enumerate(data): 6655 print(i, data_i) 6656 6657 6658 # Try write some R2eff correlations. 6659 if True: 6660 selection = None 6661 # Collect r2eff values. 6662 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6663 6664 # For all spins, mdd 6665 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6666 6667 # Plot correlation of intensity 6668 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6669 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6670 corr_data = [fig1, fig2] 6671 6672 write_stats = True 6673 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6674 6675 # Open stat file. 6676 if write_stats: 6677 for i, corr_data_i in enumerate(corr_data): 6678 data, methods, glob_inis = corr_data[i] 6679 data_x, data_y = data 6680 method_x, method_y = methods 6681 glob_ini_x, glob_ini_y = glob_inis 6682 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6683 np = len(x) 6684 6685 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6686 6687 if selection == None: 6688 file_name = file_name_ini + '_all.txt' 6689 else: 6690 file_name = file_name_ini + '_sel.txt' 6691 path = RDR.results_dir 6692 data = extract_data(file=file_name, dir=path) 6693 6694 # Loop over the lines. 6695 for i, data_i in enumerate(data): 6696 print(i, data_i) 6697 6698 6699 # Try plot some R2eff statistics. 6700 if True: 6701 # Collect r2eff values. 6702 selections = [None, ':2,3'] 6703 for selection in selections: 6704 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6705 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6706 6707 # Get R2eff stats. 6708 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6709 6710 ## Plot R2eff stats 6711 write_stats = True 6712 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6713 6714 # Open stat file. 6715 if write_stats: 6716 if selection == None: 6717 file_name = 'r2eff_stat_all.txt' 6718 else: 6719 file_name = 'r2eff_stat_sel.txt' 6720 path = RDR.results_dir 6721 data = extract_data(file=file_name, dir=path) 6722 6723 # Loop over the lines. 6724 for i, data_i in enumerate(data): 6725 print(i, data_i) 6726 6727 6728 # Do minimisation individual. 6729 if True: 6730 methods = ['FT', 'MDD'] 6731 # Now calculate R2eff. 6732 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6733 6734 min_methods = [['FT'], ['MDD']] 6735 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6736 6737 #min_methods = [['FT']] 6738 #min_list_glob_ini = [[128]] 6739 #selection = ':2,3' 6740 selection = None 6741 6742 for i, methods in enumerate(min_methods): 6743 list_glob_ini = min_list_glob_ini[i] 6744 6745 if True: 6746 # First get data. 6747 if True: 6748 # First load all data. 6749 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6750 6751 # Then set R20 6752 if True: 6753 # Set R20 from min R2eff in preparation for Grid search. 6754 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6755 6756 # Check and print parameters. 6757 if True: 6758 # Print for pipe name 6759 method = methods[0] 6760 glob_ini = list_glob_ini[0] 6761 6762 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6763 RDR.spin_display_params(pipe_name=test_pipe_name) 6764 6765 # Then Grid search. 6766 if True: 6767 # Do Grid search. 6768 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6769 6770 # Then Minimise. 6771 if True: 6772 # Minimise 6773 RDR.opt_max_iterations = int(1e2) 6774 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6775 6776 #print asd 6777 6778 # Plot statistics. 6779 # Try plot some minimisation correlations. 6780 if True: 6781 selections = [None, ':2,3'] 6782 for selection in selections: 6783 # Collect param values. 6784 analysis = 'min_ind' 6785 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6786 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6787 6788 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6789 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6790 corr_data = [fig1, fig2] 6791 6792 write_stats = True 6793 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6794 6795 # Open stat file. 6796 if write_stats: 6797 for i, corr_data_i in enumerate(corr_data): 6798 data, methods, glob_inis = corr_data[i] 6799 data_x, data_y = data 6800 method_x, method_y = methods 6801 glob_ini_x, glob_ini_y = glob_inis 6802 6803 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6804 6805 if selection == None: 6806 file_name = file_name_ini + '_all.txt' 6807 else: 6808 file_name = file_name_ini + '_sel.txt' 6809 path = RDR.results_dir 6810 data = extract_data(file=file_name, dir=path) 6811 6812 # Loop over the lines. 6813 for i, data_i in enumerate(data): 6814 print(i, data_i) 6815 6816 # Try plot some minimisation statistics. 6817 if True: 6818 # Collect param values. 6819 #selections = [None, ':2,3'] 6820 selections = [None, ':2,3'] 6821 for selection in selections: 6822 analysis = 'min_ind' 6823 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6824 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6825 6826 # Get param stats. 6827 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6828 6829 ## Plot R2eff stats 6830 write_stats = True 6831 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6832 6833 # Open stat file. 6834 if write_stats: 6835 if selection == None: 6836 file_name = '%s_stat_all.txt' % (analysis) 6837 else: 6838 file_name = '%s_stat_sel.txt' % (analysis) 6839 path = RDR.results_dir 6840 data = extract_data(file=file_name, dir=path) 6841 6842 # Loop over the lines. 6843 for i, data_i in enumerate(data): 6844 print(i, data_i) 6845 6846 6847 # Do minimisation clustered. 6848 if True: 6849 methods = ['FT', 'MDD'] 6850 # Now calculate R2eff. 6851 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6852 6853 min_methods = [['FT'], ['MDD']] 6854 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6855 6856 #min_methods = [['FT']] 6857 #min_list_glob_ini = [[128]] 6858 selection = ':2,3' 6859 6860 for i, methods in enumerate(min_methods): 6861 list_glob_ini = min_list_glob_ini[i] 6862 6863 if True: 6864 # First get data. 6865 if True: 6866 # First load all data. 6867 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6868 6869 # Then select spins. 6870 if True: 6871 # Deselect all spins. 6872 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6873 6874 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6875 6876 # Then preset values. 6877 if True: 6878 # Set k_AB for Grid search. 6879 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6880 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6881 6882 # Then set R20 6883 if True: 6884 # Set R20 from min R2eff in preparation for Grid search. 6885 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6886 6887 # Check and print parameters. 6888 if True: 6889 # Print for pipe name 6890 method = methods[0] 6891 glob_ini = list_glob_ini[0] 6892 6893 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6894 RDR.spin_display_params(pipe_name=test_pipe_name) 6895 6896 # Then Grid search. 6897 if True: 6898 # Do Grid search. 6899 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6900 6901 # Then cluster spins. 6902 if True: 6903 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6904 6905 # Then Minimise. 6906 if True: 6907 # Minimise 6908 RDR.opt_max_iterations = int(1e2) 6909 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6910 6911 # Plot statistics. 6912 # Try plot some minimisation correlations. 6913 if True: 6914 selection = ':2,3' 6915 # Collect param values. 6916 analysis = 'min' 6917 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6918 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6919 6920 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6921 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6922 corr_data = [fig1, fig2] 6923 6924 write_stats = True 6925 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6926 6927 # Open stat file. 6928 if write_stats: 6929 for i, corr_data_i in enumerate(corr_data): 6930 data, methods, glob_inis = corr_data[i] 6931 data_x, data_y = data 6932 method_x, method_y = methods 6933 glob_ini_x, glob_ini_y = glob_inis 6934 6935 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6936 6937 if selection == None: 6938 file_name = file_name_ini + '_all.txt' 6939 else: 6940 file_name = file_name_ini + '_sel.txt' 6941 path = RDR.results_dir 6942 data = extract_data(file=file_name, dir=path) 6943 6944 # Loop over the lines. 6945 for i, data_i in enumerate(data): 6946 print(i, data_i) 6947 6948 # Try plot some minimisation statistics. 6949 if True: 6950 # Collect param values. 6951 selections = [':2,3'] 6952 for selection in selections: 6953 analysis = 'min' 6954 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6955 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6956 6957 # Get param stats. 6958 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6959 6960 ## Plot R2eff stats 6961 write_stats = True 6962 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6963 6964 # Open stat file. 6965 if write_stats: 6966 if selection == None: 6967 file_name = '%s_stat_all.txt' % (analysis) 6968 else: 6969 file_name = '%s_stat_sel.txt' % (analysis) 6970 path = RDR.results_dir 6971 data = extract_data(file=file_name, dir=path) 6972 6973 # Loop over the lines. 6974 for i, data_i in enumerate(data): 6975 print(i, data_i)
6976 6977
6978 - def test_r1rho_kjaergaard_auto(self):
6979 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6980 6981 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6982 6983 This uses the automatic analysis. 6984 6985 """ 6986 6987 # Cluster residues 6988 cluster_ids = [ 6989 ":13@N", 6990 ":15@N", 6991 ":16@N", 6992 ":25@N", 6993 ":26@N", 6994 ":28@N", 6995 ":39@N", 6996 ":40@N", 6997 ":41@N", 6998 ":43@N", 6999 ":44@N", 7000 ":45@N", 7001 ":49@N", 7002 ":52@N", 7003 ":53@N"] 7004 7005 # Load the data. 7006 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7007 7008 # Test some of the sequence. 7009 self.assertEqual(len(cdp.mol), 1) 7010 self.assertEqual(cdp.mol[0].name, None) 7011 self.assertEqual(len(cdp.mol[0].res), 48) 7012 7013 # Test the chemical shift data. 7014 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 7015 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 7016 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 7017 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 7018 7019 i = 0 7020 for spin, spin_id in spin_loop(return_id=True): 7021 # Check the chemical shift. 7022 self.assertEqual(spin.chemical_shift, cs[i]) 7023 7024 # Increment the index. 7025 i += 1 7026 7027 # Initialize counter 7028 i = 0 7029 j = 0 7030 # Count instances of select/deselect 7031 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 7032 if curspin.select == True: 7033 i += 1 7034 if curspin.select == False: 7035 j += 1 7036 7037 # Test number of selected/deselected spins. 7038 self.assertEqual(i, len(cluster_ids)) 7039 self.assertEqual(j, 48-len(cluster_ids)) 7040 7041 # Check the initial setup. 7042 self.assertEqual(cdp.mol[0].res[7].num, 13) 7043 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 7044 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 7045 7046 self.assertEqual(cdp.mol[0].res[9].num, 15) 7047 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 7048 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 7049 7050 self.assertEqual(cdp.mol[0].res[10].num, 16) 7051 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 7052 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 7053 7054 self.assertEqual(cdp.mol[0].res[16].num, 25) 7055 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 7056 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 7057 7058 self.assertEqual(cdp.mol[0].res[17].num, 26) 7059 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 7060 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 7061 7062 self.assertEqual(cdp.mol[0].res[19].num, 28) 7063 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 7064 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 7065 7066 self.assertEqual(cdp.mol[0].res[29].num, 39) 7067 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 7068 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 7069 7070 self.assertEqual(cdp.mol[0].res[30].num, 40) 7071 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 7072 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 7073 7074 self.assertEqual(cdp.mol[0].res[31].num, 41) 7075 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 7076 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 7077 7078 self.assertEqual(cdp.mol[0].res[33].num, 43) 7079 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 7080 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 7081 7082 self.assertEqual(cdp.mol[0].res[34].num, 44) 7083 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 7084 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 7085 7086 self.assertEqual(cdp.mol[0].res[35].num, 45) 7087 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 7088 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 7089 7090 self.assertEqual(cdp.mol[0].res[38].num, 49) 7091 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 7092 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 7093 7094 self.assertEqual(cdp.mol[0].res[41].num, 52) 7095 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 7096 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 7097 7098 self.assertEqual(cdp.mol[0].res[42].num, 53) 7099 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 7100 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 7101 7102 # The dispersion models. 7103 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7104 7105 # The grid search size (the number of increments per dimension). 7106 GRID_INC = 4 7107 7108 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7109 MC_NUM = 3 7110 7111 # Model selection technique. 7112 MODSEL = 'AIC' 7113 7114 # Execute the auto-analysis (fast). 7115 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7116 OPT_FUNC_TOL = 1e-1 7117 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7118 OPT_MAX_ITERATIONS = 1000 7119 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7120 7121 result_dir_name = ds.tmpdir 7122 7123 # Make all spins free 7124 for curspin in cluster_ids: 7125 self.interpreter.relax_disp.cluster('free spins', curspin) 7126 # Shut them down 7127 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7128 7129 # Select only a subset of spins for global fitting 7130 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7131 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7132 7133 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7134 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7135 7136 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7137 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7138 7139 # Run the analysis. 7140 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7141 7142 # Check the kex value of residue 52 7143 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 7144 7145 # Print results for each model. 7146 print("\n\n################") 7147 print("Printing results") 7148 print("################\n") 7149 for model in MODELS: 7150 # Skip R2eff model. 7151 if model == MODEL_R2EFF: 7152 continue 7153 7154 # Switch to pipe. 7155 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 7156 print("\nModel: %s" % (model)) 7157 7158 # Loop over the spins. 7159 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7160 # Generate spin string. 7161 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 7162 7163 # Loop over the parameters. 7164 print("Optimised parameters for spin: %s" % (spin_string)) 7165 for param in cur_spin.params + ['chi2']: 7166 # Get the value. 7167 if param in ['r1', 'r2']: 7168 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 7169 # Generate the R20 key. 7170 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 7171 7172 # Get the value. 7173 value = getattr(cur_spin, param)[r20_key] 7174 7175 # Print value. 7176 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7177 7178 # For all other parameters. 7179 else: 7180 # Get the value. 7181 value = getattr(cur_spin, param) 7182 7183 # Print value. 7184 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7185 7186 # Print the final pipe. 7187 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 7188 print("\nFinal pipe")
7189 7190
7192 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 7193 7194 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7195 7196 This uses the automatic analysis. 7197 7198 """ 7199 7200 # Cluster residues 7201 cluster_ids = [ 7202 ":52@N"] 7203 7204 # Load the data. 7205 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7206 7207 # The dispersion models. 7208 MODELS = [MODEL_R2EFF] 7209 7210 # The grid search size (the number of increments per dimension). 7211 GRID_INC = 4 7212 7213 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7214 MC_NUM = 3 7215 7216 # Model selection technique. 7217 MODSEL = 'AIC' 7218 7219 # Execute the auto-analysis (fast). 7220 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7221 OPT_FUNC_TOL = 1e-1 7222 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7223 OPT_MAX_ITERATIONS = 1000 7224 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7225 7226 result_dir_name = ds.tmpdir 7227 7228 # Make all spins free 7229 for curspin in cluster_ids: 7230 self.interpreter.relax_disp.cluster('free spins', curspin) 7231 # Shut them down 7232 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7233 7234 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7235 7236 # Run the analysis. 7237 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7238 7239 # Check the graphs produced. 7240 graph_comb = [ 7241 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 7242 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 7243 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 7244 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 7245 ] 7246 7247 # Define expected folder names. 7248 result_folders = MODELS 7249 7250 # Assign spin_id. 7251 spin_id = ':52@N' 7252 7253 # Loop over result folders. 7254 for result_folder in result_folders: 7255 # Skip the model R2eff, which does not produce graphs. 7256 if result_folder == MODEL_R2EFF: 7257 continue 7258 7259 # Loop over graphs. 7260 for y_axis, x_axis, interpolate in graph_comb: 7261 # Determine file name: 7262 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7263 7264 # Make the file name. 7265 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7266 7267 # Get the file path. 7268 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 7269 7270 print("Testing file access to graph: %s"%file_path) 7271 self.assert_(access(file_path, F_OK)) 7272 7273 # Start testing all possible combinations of graphs. 7274 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 7275 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 7276 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 7277 7278 result_dir_name = ds.tmpdir 7279 7280 # Loop through all possible combinations of y_axis, x_axis and interpolation. 7281 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 7282 7283 for result_folder in result_folders: 7284 # Skip the model R2eff, which does not produce graphs. 7285 if result_folder == MODEL_R2EFF: 7286 continue 7287 7288 for y_axis in y_axis_types: 7289 for x_axis in x_axis_types: 7290 for interpolate in interpolate_types: 7291 # Determine file name: 7292 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7293 7294 # Make the file name. 7295 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7296 7297 # Write the curves. 7298 dir = result_dir_name+sep+result_folder 7299 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7300 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7301 7302 # Get the file path. 7303 file_path = get_file_path(file_name, dir) 7304 7305 # Test the plot file exists. 7306 print("Testing file access to graph: %s"%file_path) 7307 self.assert_(access(file_path, F_OK)) 7308 7309 # Now open, and compare content, line by line. 7310 file_prod = open(file_path) 7311 lines_prod = file_prod.readlines() 7312 file_prod.close() 7313 7314 # Define file to compare against. 7315 dir_comp = data_path+sep+result_folder 7316 file_path_comp = get_file_path(file_name, dir_comp) 7317 file_comp = open(file_path_comp) 7318 lines_comp = file_comp.readlines() 7319 file_comp.close() 7320 7321 # Assert number of lines is equal. 7322 self.assertEqual(len(lines_prod), len(lines_comp)) 7323 for j in range(len(lines_prod)): 7324 # Make the string test 7325 first_char = lines_prod[j][0] 7326 if first_char in ["@", "&"]: 7327 self.assertEqual(lines_prod[j], lines_comp[j]) 7328 else: 7329 # Split string in x, y, error. 7330 # The error would change per run. 7331 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7332 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7333 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7334 self.assertAlmostEqual(float(y_prod), float(y_comp))
7335 7336
7338 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7339 7340 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7341 7342 This uses the automatic analysis, with missing loading R1. 7343 7344 """ 7345 7346 # Cluster residues 7347 cluster_ids = [ 7348 ":13@N", 7349 ":15@N", 7350 ":16@N", 7351 ":25@N", 7352 ":26@N", 7353 ":28@N", 7354 ":39@N", 7355 ":40@N", 7356 ":41@N", 7357 ":43@N", 7358 ":44@N", 7359 ":45@N", 7360 ":49@N", 7361 ":52@N", 7362 ":53@N"] 7363 7364 # Load the data. 7365 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7366 7367 # The dispersion models. 7368 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7369 7370 # The grid search size (the number of increments per dimension). 7371 GRID_INC = None 7372 7373 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7374 MC_NUM = 3 7375 7376 # Model selection technique. 7377 MODSEL = 'AIC' 7378 7379 # Execute the auto-analysis (fast). 7380 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7381 OPT_FUNC_TOL = 1e-25 7382 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7383 OPT_MAX_ITERATIONS = 10000000 7384 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7385 7386 result_dir_name = ds.tmpdir 7387 7388 # Make all spins free 7389 for curspin in cluster_ids: 7390 self.interpreter.relax_disp.cluster('free spins', curspin) 7391 # Shut them down 7392 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7393 7394 # Select only a subset of spins for global fitting 7395 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7396 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7397 7398 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7399 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7400 7401 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7402 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7403 7404 # Point to directory with R2eff values, with 2000 MC simulations. 7405 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 7406 7407 r1_fit = True 7408 7409 # Run the analysis. 7410 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 7411 7412 # Verify the data. 7413 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7414 7415
7416 - def test_r2eff_read(self):
7417 """Test the operation of the relax_disp.r2eff_read user function.""" 7418 7419 # The path to the data files. 7420 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7421 7422 # Read the sequence data. 7423 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7424 7425 # The ID. 7426 id = 'test' 7427 7428 # Set up the metadata. 7429 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7430 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7431 7432 # Try reading the file. 7433 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7434 7435 # Check the global data. 7436 data = [ 7437 ['cpmg_frqs', {'test': 66.667}], 7438 ['cpmg_frqs_list', [66.667]], 7439 ['dispersion_points', 1], 7440 ['exp_type', {'test': 'SQ CPMG'}], 7441 ['exp_type_list', ['SQ CPMG']], 7442 ['spectrometer_frq', {'test': 800000000.0}], 7443 ['spectrometer_frq_count', 1], 7444 ['spectrometer_frq_list', [800000000.0]], 7445 ['spectrum_ids', ['test']] 7446 ] 7447 for name, value in data: 7448 # Does it exist? 7449 self.assert_(hasattr(cdp, name)) 7450 7451 # Check the object. 7452 obj = getattr(cdp, name) 7453 self.assertEqual(obj, value) 7454 7455 # Check the spin data. 7456 data = [ 7457 [1, 2.3035747e+04, 8.5467725e+01], 7458 [2, 9.9629762e+04, 2.8322033e+02], 7459 [3, 9.5663137e+04, 2.8632929e+02], 7460 [4, 1.7089893e+05, 3.1089428e+02], 7461 [5, 4.7323876e+04, 1.0084269e+02], 7462 [6, 2.0199122e+04, 1.0135220e+02], 7463 [7, 1.6655488e+05, 3.1609061e+02], 7464 [8, 9.0061074e+04, 1.9176585e+02], 7465 [10, 8.4726204e+04, 2.8898155e+02], 7466 [11, 1.5050233e+05, 4.3138029e+02], 7467 [12, 9.2998531e+04, 3.0440191e+02], 7468 [13, 1.6343507e+05, 3.3144097e+02], 7469 [14, 1.0137301e+05, 3.7314642e+02], 7470 [15, 8.3407837e+04, 1.6546473e+02], 7471 [16, 1.3819126e+05, 3.3388517e+02], 7472 [17, 1.1010490e+05, 3.5639222e+02], 7473 [18, 9.4324035e+04, 3.2343585e+02], 7474 [19, 1.1135179e+05, 3.0706671e+02], 7475 [20, 7.6339410e+04, 1.7377460e+02], 7476 [21, 6.2008453e+04, 1.7327150e+02], 7477 [22, 1.0590404e+05, 2.4814635e+02], 7478 [23, 1.0630198e+05, 2.3601100e+02], 7479 [24, 7.2996320e+04, 1.4952465e+02], 7480 [25, 9.5486742e+04, 2.7080766e+02], 7481 [26, 5.8067989e+04, 1.6820462e+02], 7482 [27, -1.7168510e+04, 2.2519560e+02], 7483 [28, 1.6891473e+05, 2.3497525e+02], 7484 [29, 9.4038555e+04, 2.0357593e+02], 7485 [30, 2.1386951e+04, 2.2153532e+02], 7486 [31, 9.3982899e+04, 2.0937056e+02], 7487 [32, 8.6097484e+04, 2.3868467e+02], 7488 [33, 1.0194337e+05, 2.7370704e+02], 7489 [34, 8.5683111e+04, 2.0838076e+02], 7490 [35, 8.6985768e+04, 2.0889310e+02], 7491 [36, 8.6011237e+04, 1.7498390e+02], 7492 [37, 1.0984097e+05, 2.7622998e+02], 7493 [38, 8.7017879e+04, 2.6547994e+02], 7494 [39, 9.1682649e+04, 5.2777676e+02], 7495 [40, 7.6370440e+04, 1.9873214e+02], 7496 [41, 9.1393531e+04, 2.4483824e+02], 7497 [42, 1.1017111e+05, 2.8020699e+02], 7498 [43, 9.4552366e+04, 3.4394150e+02], 7499 [44, 1.2858281e+05, 6.8449252e+02], 7500 [45, 7.4583525e+04, 1.9544210e+02], 7501 [46, 9.2087490e+04, 2.0491066e+02], 7502 [47, 9.7507255e+04, 2.5162839e+02], 7503 [48, 1.0033842e+05, 2.7566430e+02], 7504 [49, 1.3048305e+05, 2.6797466e+02], 7505 [50, 1.0546796e+05, 1.9304384e+02], 7506 [51, 9.3099697e+04, 2.0773311e+02], 7507 [52, 4.6863758e+04, 1.3169068e+02], 7508 [53, 6.1055806e+04, 1.5448477e+02], 7509 [55, 6.8629994e+04, 1.6868673e+02], 7510 [56, 1.1005552e+05, 2.1940465e+02], 7511 [57, 1.0572760e+05, 1.9768486e+02], 7512 [58, 1.1176950e+05, 3.0009610e+02], 7513 [59, 9.8758603e+04, 3.3803895e+02], 7514 [60, 9.9517201e+04, 3.5137994e+02], 7515 [61, 5.4357946e+04, 2.5896579e+02], 7516 [62, 1.0899978e+05, 2.8720371e+02], 7517 [63, 8.4549759e+04, 4.1401837e+02], 7518 [64, 5.5014550e+04, 2.1135781e+02], 7519 [65, 8.0569666e+04, 2.3249709e+02], 7520 [66, 1.2936610e+05, 3.5218725e+02], 7521 [67, 3.6438010e+04, 8.7924003e+01], 7522 [70, 3.8763157e+04, 1.3325040e+02], 7523 [71, 8.5711411e+04, 2.9316183e+02], 7524 [72, 3.3211541e+04, 1.2182123e+02], 7525 [73, 3.2070576e+04, 1.2305430e+02] 7526 ] 7527 for res_num, value, error in data: 7528 # Get the spin. 7529 spin = return_spin(spin_id=":%s"%res_num) 7530 7531 # Check the values. 7532 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7533 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7534 7535
7536 - def test_r2eff_read_spin(self):
7537 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7538 7539 # The path to the data files. 7540 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7541 7542 # Generate the sequence. 7543 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7544 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7545 self.interpreter.spin.isotope('1H', spin_id='@H') 7546 self.interpreter.spin.isotope('15N', spin_id='@N') 7547 7548 # Build the experiment IDs. 7549 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7550 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7551 ids = [] 7552 for value in H_disp_points: 7553 ids.append('1H_CPMG_%s' % value) 7554 for value in N_disp_points: 7555 ids.append('15N_CPMG_%s' % value) 7556 print("\n\nThe experiment IDs are %s." % ids) 7557 7558 # Set up the metadata for the experiments. 7559 for id in ids: 7560 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7561 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7562 for value in H_disp_points: 7563 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7564 for value in N_disp_points: 7565 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7566 7567 # Loop over the experiments. 7568 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7569 # Try reading the file. 7570 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7571 7572 # Check the global data. 7573 data = [ 7574 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7575 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7576 ['dispersion_points', 24], 7577 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7578 ['exp_type_list', ['SQ CPMG']], 7579 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7580 ['spectrometer_frq_count', 1], 7581 ['spectrometer_frq_list', [500000000.0]], 7582 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7583 ] 7584 for name, value in data: 7585 # Does it exist? 7586 self.assert_(hasattr(cdp, name)) 7587 7588 # Check the object. 7589 obj = getattr(cdp, name) 7590 if not isinstance(data, dict): 7591 self.assertEqual(obj, value) 7592 7593 # Check the global dictionary data. 7594 else: 7595 for id in ids: 7596 self.assertEqual(obj[id], value[id]) 7597 7598 # Check the spin data. 7599 h_data = [ 7600 [ 67.0, 21.47924, 0.42958], 7601 [ 133.0, 16.73898, 0.33478], 7602 [ 267.0, 9.97357, 0.19947], 7603 [ 400.0, 8.23877, 0.24737], 7604 [ 533.0, 7.59290, 0.24263], 7605 [ 667.0, 7.45843, 0.24165], 7606 [ 800.0, 7.11222, 0.23915], 7607 [ 933.0, 7.40880, 0.24129], 7608 [1067.0, 6.55191, 0.16629], 7609 [1600.0, 6.72177, 0.23637], 7610 [2133.0, 7.09629, 0.23904], 7611 [2667.0, 7.14675, 0.23940] 7612 ] 7613 for disp_point, value, error in h_data: 7614 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7615 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7616 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7617 n_data = [ 7618 [ 50.0, 27.15767, 0.54315], 7619 [ 100.0, 26.55781, 0.53116], 7620 [ 150.0, 24.73462, 0.49469], 7621 [ 200.0, 20.98617, 0.41972], 7622 [ 250.0, 17.82442, 0.35649], 7623 [ 300.0, 15.55352, 0.31107], 7624 [ 350.0, 13.78958, 0.27579], 7625 [ 400.0, 12.48334, 0.24967], 7626 [ 500.0, 11.55724, 0.23114], 7627 [ 600.0, 10.53874, 0.21077], 7628 [ 700.0, 10.07395, 0.20148], 7629 [ 800.0, 9.62952, 0.19259], 7630 [ 900.0, 9.49994, 0.19000], 7631 [1000.0, 8.71350, 0.17427] 7632 ] 7633 for disp_point, value, error in n_data: 7634 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7635 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7636 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7637 7638
7639 - def test_r2eff_fit_fixed_time(self):
7640 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7641 7642 # Execute the script. 7643 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7644 7645
7646 - def test_read_r2eff(self):
7647 """Test the reading of a file containing r2eff values.""" 7648 7649 # Create the sequence data, and name the spins. 7650 self.interpreter.residue.create(1, 'Gly') 7651 self.interpreter.residue.create(2, 'Gly') 7652 self.interpreter.residue.create(3, 'Gly') 7653 7654 # Read the file. 7655 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7656 7657 # Test the data. 7658 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7659 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7660 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7661 7662
7664 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 7665 7666 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7667 7668 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7669 'SOD1-WT' CPMG data to the CR72 dispersion model. 7670 7671 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7672 Data is for experiment at 25 degree Celcius. 7673 """ 7674 7675 # Base data setup. 7676 pipe_name = 'base pipe' 7677 pipe_type = 'relax_disp' 7678 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7679 select_spin_index = list(range(0, 1)) 7680 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7681 7682 # Generate r20 key. 7683 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7684 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7685 7686 ## Now prepare for MODEL calculation. 7687 MODEL = "CR72" 7688 7689 # Change pipe. 7690 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7691 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7692 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7693 7694 # Then select model. 7695 self.interpreter.relax_disp.select_model(model=MODEL) 7696 7697 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7698 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7699 7700 # Test result, for normal run. 7701 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7702 # Get the spin_params. 7703 spin_params = spin.params 7704 7705 # Defined fixed values for testing. 7706 if spin_id == ":10@N": 7707 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7708 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7709 7710 # Print out. 7711 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7712 7713 # Testing the r2 values for the different fields are not the same. 7714 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7715 7716 # Test values are larger than 0. 7717 self.assert_(spin.r2[r20_key_600] > 0.0) 7718 self.assert_(spin.r2[r20_key_500] > 0.0) 7719 7720 # Loop over the experiment settings. 7721 r2eff_600 = [] 7722 r2eff_500 = [] 7723 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7724 # Create the data key. 7725 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7726 7727 # Extract the r2 eff data. 7728 r2eff = spin.r2eff[data_key] 7729 if frq == 599.8908617*1E6: 7730 r2eff_600.append(r2eff) 7731 elif frq == 499.862139*1E6: 7732 r2eff_500.append(r2eff) 7733 7734 # Sort values. 7735 r2eff_600.sort() 7736 r2eff_500.sort() 7737 7738 # Test values again. 7739 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7740 print(r2eff_600) 7741 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7742 print("") 7743 7744 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7745 print(r2eff_500) 7746 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7747 print("") 7748 7749 print("###########################################") 7750 print("Trying GRID SEARCH for minimum R2eff values") 7751 7752 ### Test just the Grid search. 7753 GRID_INC = 5 7754 7755 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7756 7757 ### Then test the value.set function. 7758 # Change pipe. 7759 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7760 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7761 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7762 7763 # Then select model. 7764 self.interpreter.relax_disp.select_model(model=MODEL) 7765 7766 # Then set the standard parameter values. 7767 for param in spin_params: 7768 print("Setting standard parameter for param: %s"%param) 7769 self.interpreter.value.set(param=param, index=None) 7770 7771 # Test result, for normal run. 7772 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7773 # Print out. 7774 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7775 7776 # Testing the r2 values. 7777 self.assertEqual(spin.r2[r20_key_600], 10.00) 7778 self.assertEqual(spin.r2[r20_key_500], 10.00) 7779 self.assertEqual(spin.pA, 0.9) 7780 self.assertEqual(spin.dw, 1.0) 7781 self.assertEqual(spin.kex, 1000.0) 7782 7783 print("###########################################") 7784 print("Trying GRID SEARCH for standard R2eff values") 7785 7786 ### Test just the Grid search. 7787 GRID_INC = 5 7788 7789 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7790 7791 ### Run auto_analysis. 7792 # The grid search size (the number of increments per dimension). 7793 GRID_INC = 5 7794 7795 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7796 MC_NUM = 3 7797 7798 # Model selection technique. 7799 MODSEL = 'AIC' 7800 7801 # Execute the auto-analysis (fast). 7802 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7803 OPT_FUNC_TOL = 1e-1 7804 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7805 OPT_MAX_ITERATIONS = 1000 7806 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7807 7808 # Run the analysis. 7809 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7810 7811
7812 - def test_show_apod_extract(self):
7813 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7814 7815 # The path to the data files. 7816 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7817 7818 # Define file name. 7819 file_name = '128_0_FT.ft2' 7820 7821 # Call function. 7822 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7823 7824 # Define how output should look like. 7825 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7826 # Dont test lines which can differ. 7827 show_apod_ver = [ 7828 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7829 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7830 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7831 '', 7832 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7833 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7834 #'', 7835 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7836 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7837 7838 for i, line in enumerate(show_apod_ver): 7839 line_ver = get_output[i] 7840 7841 print(line) 7842 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7843 continue 7844 # Make the string test 7845 self.assertEqual(line, line_ver)
7846 7847
7848 - def test_show_apod_rmsd(self):
7849 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7850 7851 # The path to the data files. 7852 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7853 7854 # Define file name. 7855 file_name = '128_0_FT.ft2' 7856 7857 # Call function. 7858 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7859 7860 # Assert. 7861 self.assertEqual(rmsd, 8583.41)
7862 7863
7865 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7866 7867 # The path to the data files. 7868 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7869 7870 # Call function, and get all file names. 7871 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7872 7873 # Loop over file_paths. 7874 for wfile_path in wfile_paths: 7875 # Open the file. 7876 get_data = extract_data(file=wfile_path) 7877 7878 # Extract line 0, column 0. 7879 test = float(get_data[0][0]) 7880 7881 # Assert. 7882 self.assertEqual(test, 8583.41)
7883 7884
7886 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7887 7888 # The path to the data files. 7889 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7890 7891 # Define file name. 7892 file_name = '128_0_FT.ft2' 7893 7894 # Call function, and get file name. 7895 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7896 7897 # Open the file. 7898 get_data = extract_data(file=wfile_path) 7899 7900 # Extract line 0, column 0. 7901 test = float(get_data[0][0]) 7902 7903 # Assert. 7904 self.assertEqual(test, 8583.41)
7905 7906
7908 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7909 7910 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7911 'SOD1-WT' CPMG data to the CR72 dispersion model. 7912 7913 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7914 Data is for experiment at 25 degree Celcius. 7915 7916 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7917 """ 7918 7919 # Base data setup. 7920 pipe_name = 'base pipe' 7921 pipe_type = 'relax_disp' 7922 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7923 select_spin_index = list(range(0, 1)) 7924 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7925 7926 # Define replicated 7927 repl_A = ['Z_A1', 'Z_A15'] 7928 repl_B = ['Z_B1', 'Z_B18'] 7929 7930 # Loop over spectrum ID, and sort them 7931 spectrum_ids_A = [] 7932 spectrum_ids_B = [] 7933 for spectrum_id in cdp.spectrum_ids: 7934 if "A" in spectrum_id: 7935 spectrum_ids_A.append(spectrum_id) 7936 elif "B" in spectrum_id: 7937 spectrum_ids_B.append(spectrum_id) 7938 7939 # To clean up old error analysis, delete attributes 7940 delattr(cdp, "var_I") 7941 delattr(cdp, "sigma_I") 7942 7943 # Perform error analysis 7944 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7945 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7946 7947 # Loop over spins, save errors to list 7948 Errors_A_B = [] 7949 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7950 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7951 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7952 Errors_A_B.append([A_err, B_err]) 7953 7954 # To clean up old error analysis, delete attributes 7955 delattr(cdp, "var_I") 7956 delattr(cdp, "sigma_I") 7957 7958 # Perform error analysis. Order is important 7959 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7960 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7961 7962 # Loop over spins, save errors to list 7963 Errors_B_A = [] 7964 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7965 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7966 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7967 Errors_B_A.append([A_err, B_err]) 7968 7969 # Make test for order of error 7970 for i in range(len(Errors_A_B)): 7971 Error_A_B = Errors_A_B[i] 7972 Error_B_A = Errors_B_A[i] 7973 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7974 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7975 7976 # Make further tests for fixed values 7977 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7978 std_A_fix = 2785.7263335738567 7979 7980 for id_A in spectrum_ids_A: 7981 self.assertEqual(cdp.sigma_I[id_A], std_A) 7982 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7983 7984 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7985 std_B_fix = 4967.3772030667988 7986 7987 for id_B in spectrum_ids_B: 7988 self.assertEqual(cdp.sigma_I[id_B], std_B) 7989 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7990 7991
7992 - def test_sod1wt_t25_to_cr72(self):
7993 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7994 7995 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7996 'SOD1-WT' CPMG data to the CR72 dispersion model. 7997 7998 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7999 Data is for experiment at 25 degree Celcius. 8000 """ 8001 8002 # Base data setup. 8003 pipe_name = 'base pipe' 8004 pipe_type = 'relax_disp' 8005 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 8006 select_spin_index = list(range(0, 2)) 8007 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 8008 8009 # Generate r20 key. 8010 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8011 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8012 8013 ## Now prepare for MODEL calculation. 8014 MODEL = "CR72" 8015 8016 # Change pipe. 8017 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 8018 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 8019 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 8020 8021 # Then select model. 8022 self.interpreter.relax_disp.select_model(model=MODEL) 8023 8024 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 8025 GRID_INC = 7 8026 8027 # Store grid and minimisations results. 8028 grid_results = [] 8029 mini_results = [] 8030 clust_results = [] 8031 8032 # Set the R20 parameters in the default grid search using the minimum R2eff value. 8033 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 8034 8035 # Deselect insignificant spins. 8036 self.interpreter.relax_disp.insignificance(level=1.0) 8037 8038 # Perform Grid Search. 8039 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 8040 8041 # Store result. 8042 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8043 # Store grid results. 8044 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8045 8046 ## Now do minimisation. 8047 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8048 set_func_tol = 1e-9 8049 set_max_iter = 100000 8050 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 8051 8052 # Store result. 8053 pA_values = [] 8054 kex_values = [] 8055 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8056 # Store minimisation results. 8057 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8058 8059 # Store pA values. 8060 pA_values.append(spin.pA) 8061 8062 # Store kex values. 8063 kex_values.append(spin.kex) 8064 8065 print("\n# Now print before and after minimisation.\n") 8066 8067 # Print results. 8068 for i in range(len(grid_results)): 8069 # Get values. 8070 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 8071 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 8072 8073 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 8074 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 8075 8076 ## Prepare for clustering 8077 # Change pipe. 8078 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 8079 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 8080 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 8081 8082 # Then select model. 8083 self.interpreter.relax_disp.select_model(model=MODEL) 8084 8085 # Define cluster id. 8086 cluster_id = 'clust' 8087 8088 # Loop over spins to cluster them. 8089 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8090 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 8091 8092 # Copy over values. 8093 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 8094 8095 # Test the median values is correct 8096 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8097 print(pA_values) 8098 # The the median pA value returned. 8099 self.assertEqual(median(pA_values), spin.pA) 8100 8101 # The the median kex value returned. 8102 self.assertEqual(median(kex_values), spin.kex) 8103 8104 ## Now do minimisation. 8105 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 8106 8107 # Store result. 8108 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8109 # Store clust results. 8110 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8111 8112 # Store the outcome of the clustering minimisation. 8113 clust_pA = spin.pA 8114 clust_kex = spin.kex 8115 8116 print("\n# Now testing.\n") 8117 8118 # Define results 8119 test_res = {} 8120 test_res[':10@N'] = {} 8121 test_res[':10@N']['r2600'] = 18.429755324773360 8122 test_res[':10@N']['r2500'] = 16.981349161968630 8123 test_res[':10@N']['dw'] = 2.700755859433969 8124 test_res[':10@N']['pA'] = 0.971531659288657 8125 test_res[':10@N']['kex'] = 3831.766337047963134 8126 test_res[':11@N'] = {} 8127 test_res[':11@N']['r2600'] = 18.193409421115213 8128 test_res[':11@N']['r2500'] = 17.308838135567765 8129 test_res[':11@N']['dw'] = 2.706650302761793 8130 test_res[':11@N']['pA'] = 0.971531659288657 8131 test_res[':11@N']['kex'] = 3831.766337047963134 8132 8133 # Then make tests. 8134 for i in range(len(grid_results)): 8135 # Get values. 8136 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 8137 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 8138 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 8139 8140 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 8141 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 8142 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 8143 8144 # Make tests. 8145 self.assertEqual(clust_pA, c_pA) 8146 self.assertEqual(clust_kex, c_kex) 8147 8148 # Test values. 8149 if c_spin_id in test_res: 8150 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 8151 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 8152 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 8153 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 8154 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
8155 8156 # Save disp graph to temp. 8157 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 8158 8159
8161 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 8162 8163 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 8164 'SOD1-WT' CPMG data to the CR72 dispersion model. 8165 8166 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 8167 Data is for experiment at 25 degree Celcius. 8168 """ 8169 8170 # Base data setup. 8171 pipe_name = 'base pipe' 8172 pipe_type = 'relax_disp' 8173 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 8174 select_spin_index = list(range(0, 2)) 8175 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 8176 8177 # Generate r20 key. 8178 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8179 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8180 8181 # Cluster everything, to analyse together. 8182 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 8183 8184 # Write input 8185 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 8186 8187 # Check the r2eff set files. 8188 print("\nChecking the R2eff input set files.") 8189 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 8190 8191 # First check file exists 8192 for dir, file in files: 8193 print(dir+sep+file) 8194 self.assert_(access(dir+sep+file, F_OK)) 8195 8196 # Define how files should look like 8197 data_set_600 = [ 8198 "60.8272464287\n", 8199 "0.06\n", 8200 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8201 "# G10\n", 8202 " 33.333 26.53556078711 0.5236104771163\n", 8203 " 66.667 25.29735243318 0.48766574122\n", 8204 " 100 25.09470361403 0.4820438864671\n", 8205 " 133.333 25.15603274331 0.4837377286085\n", 8206 " 166.667 24.27213341753 0.4599457904395\n", 8207 " 200 24.00364120328 0.4529773198905\n", 8208 " 266.667 24.03511395168 0.4537880662536\n", 8209 " 300 23.04761040024 0.4291039120557\n", 8210 " 333.333 22.95530300787 0.4268745963972\n", 8211 " 400 23.06158810662 0.4294426293624\n", 8212 " 466.667 22.26799054092 0.4106809618644\n", 8213 " 533.333 21.99851418823 0.4045232104735\n", 8214 " 666.667 21.19651570955 0.3868136173831\n", 8215 " 833.333 20.30938498379 0.3682604887899\n", 8216 " 1000 20.28273252609 0.367719392568\n", 8217 "# D11\n", 8218 " 33.333 24.76520269878 0.5026475808706\n", 8219 " 66.667 24.8773107448 0.5058752916906\n", 8220 " 100 24.90357815239 0.5066348551479\n", 8221 " 133.333 23.7782506151 0.4751950583865\n", 8222 " 166.667 23.68548762076 0.4727017128631\n", 8223 " 200 23.58629651618 0.4700517377679\n", 8224 " 266.667 23.47734671187 0.4671601744044\n", 8225 " 300 24.08647493772 0.4835855560598\n", 8226 " 333.333 22.98314371029 0.4542918950801\n", 8227 " 400 22.80339361568 0.4497107885587\n", 8228 " 466.667 22.91634335366 0.4525833037874\n", 8229 " 533.333 22.59774140046 0.4445334311324\n", 8230 " 666.667 20.9177750759 0.4046955726046\n", 8231 " 833.333 20.71792550566 0.4002363835007\n", 8232 " 1000 19.54080006349 0.3751112751853\n", 8233 ] 8234 8235 # Check data_set_600 8236 file = open(files[0][0]+sep+files[0][1]) 8237 lines = file.readlines() 8238 file.close() 8239 self.assertEqual(len(data_set_600), len(lines)) 8240 for i in range(len(data_set_600)): 8241 # Make the string test 8242 self.assertEqual(data_set_600[i], lines[i]) 8243 8244 # Define how files should look like 8245 data_set_500 = [ 8246 "50.6846152368\n", 8247 "0.04\n", 8248 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8249 "# G10\n", 8250 " 50 22.28084307393 0.2944966344183\n", 8251 " 100 21.93494977761 0.2910362768307\n", 8252 " 150 21.09850032232 0.282892238351\n", 8253 " 200 20.86493960397 0.2806737853646\n", 8254 " 250 20.75287269752 0.2796178205016\n", 8255 " 300 20.25597152406 0.2750013546989\n", 8256 " 350 19.92172163467 0.2719555756504\n", 8257 " 400 19.97712052922 0.272457105051\n", 8258 " 450 19.46807010415 0.2678972122793\n", 8259 " 500 19.76875460947 0.2705774849203\n", 8260 " 550 19.39161367402 0.2672216964327\n", 8261 " 600 19.03949517697 0.2641417899694\n", 8262 " 650 19.12218812132 0.2648605059901\n", 8263 " 700 19.01037461457 0.2638893584683\n", 8264 " 800 18.83395162904 0.2623674321143\n", 8265 " 900 18.47529972436 0.2593123604687\n", 8266 " 1000 18.5252023121 0.2597343394038\n", 8267 "# D11\n", 8268 " 50 22.15403890237 0.3285588379827\n", 8269 " 100 21.80946781746 0.3247185598713\n", 8270 " 150 21.77715415505 0.324361526682\n", 8271 " 200 21.41647464235 0.3204122024881\n", 8272 " 250 21.17099940822 0.3177616325958\n", 8273 " 300 21.03740030577 0.3163316496664\n", 8274 " 350 20.95393648281 0.3154427665172\n", 8275 " 400 20.93311399332 0.315221543436\n", 8276 " 450 20.18219905222 0.3073848655291\n", 8277 " 500 19.93599065085 0.3048744697057\n", 8278 " 550 19.68475725452 0.3023424499113\n", 8279 " 600 19.33575433934 0.2988741928798\n", 8280 " 650 19.53915692194 0.3008886196853\n", 8281 " 700 19.2018754351 0.2975587767134\n", 8282 " 800 18.82360965368 0.2938866923878\n", 8283 " 900 18.71861761238 0.2928790380131\n", 8284 " 1000 17.95878049287 0.2857341721151\n", 8285 ] 8286 8287 # Check data_set_500 8288 file = open(files[1][0]+sep+files[1][1]) 8289 lines = file.readlines() 8290 file.close() 8291 self.assertEqual(len(data_set_500), len(lines)) 8292 for i in range(len(data_set_500)): 8293 # Make the string test 8294 self.assertEqual(data_set_500[i], lines[i]) 8295 8296 # Test local dir tests. This will be turned off in system test. 8297 turn_on_local_dir_test = False 8298 8299 if turn_on_local_dir_test: 8300 ## Now check to local folder with None argument. 8301 # Write input 8302 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8303 8304 # Check the r2eff set files. 8305 print("\nChecking the R2eff input set files.") 8306 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8307 8308 # First check file exists 8309 for dir, file in files: 8310 print(dir+sep+file) 8311 self.assert_(access(dir+sep+file, F_OK)) 8312 8313 ## Now check to local folder with dir argument. 8314 # Write input 8315 set_dir = "Test_ShereKhan" 8316 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8317 8318 # Check the r2eff set files. 8319 print("\nChecking the R2eff input set files.") 8320 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8321 8322 # First check file exists 8323 for dir, file in files: 8324 print(dir+sep+file) 8325 self.assert_(access(dir+sep+file, F_OK))
8326 8327
8328 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8329 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8330 8331 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 8332 """ 8333 8334 # Reset. 8335 self.interpreter.reset() 8336 8337 # Create the data pipe and load the base data. 8338 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8339 self.interpreter.state.load(data_path+sep+'r2eff_values') 8340 8341 # The model data pipe. 8342 model = 'MMQ CR72' 8343 pipe_name = "%s - relax_disp" % model 8344 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8345 self.interpreter.pipe.switch(pipe_name=pipe_name) 8346 8347 # Set the model. 8348 self.interpreter.relax_disp.select_model(model=model) 8349 8350 # Cluster everything. 8351 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8352 8353 # Copy the data. 8354 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8355 8356 # Alias the spins. 8357 spin135S = cdp.mol[0].res[0].spin[0] 8358 spin135F = cdp.mol[0].res[0].spin[1] 8359 spin137S = cdp.mol[0].res[1].spin[0] 8360 spin137F = cdp.mol[0].res[1].spin[1] 8361 8362 # The R20 keys. 8363 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8364 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8365 8366 # Set the cluster specific parameters (only for the first spin). 8367 spin135S.pA = 0.836591763632 8368 spin135S.kex = 241.806525261 8369 8370 # Set the initial parameter values. 8371 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8372 spin135S.dw = 0.583003118785 8373 spin135S.dwH = 0.0361441944301 8374 8375 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8376 spin135F.dw = 0.805849745104 8377 spin135F.dwH = 0.0215791945715 8378 8379 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8380 spin137S.dw = 0.688107568372 8381 spin137S.dwH = 0.0344463604043 8382 8383 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8384 spin137F.dw = 0.94978299907 8385 spin137F.dwH = 1.4818877939e-07 8386 8387 # Low precision optimisation. 8388 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8389 8390 # Printout. 8391 print("\n\nOptimised parameters:\n") 8392 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8393 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8394 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8395 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8396 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8397 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8398 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8399 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8400 print("\n # Set the cluster specific parameters (only for the first spin).") 8401 print(" spin135S.pA = %s" % spin135S.pA) 8402 print(" spin135S.kex = %s" % spin135S.kex) 8403 print("\n # Set the initial parameter values.") 8404 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8405 print(" spin135S.dw = %s" % spin135S.dw) 8406 print(" spin135S.dwH = %s" % spin135S.dwH) 8407 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8408 print(" spin135F.dw = %s" % spin135F.dw) 8409 print(" spin135F.dwH = %s" % spin135F.dwH) 8410 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8411 print(" spin137S.dw = %s" % spin137S.dw) 8412 print(" spin137S.dwH = %s" % spin137S.dwH) 8413 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8414 print(" spin137F.dw = %s" % spin137F.dw) 8415 print(" spin137F.dwH = %s" % spin137F.dwH) 8416 8417 # Checks for residue :135S. 8418 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8419 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8420 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8421 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8422 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8423 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8424 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8425 8426 # Checks for residue :135F. 8427 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8428 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8429 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8430 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8431 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8432 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8433 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8434 8435 # Checks for residue :137S. 8436 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8437 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8438 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8439 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8440 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8441 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8442 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8443 8444 # Checks for residue :137F. 8445 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8446 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8447 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8448 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8449 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8450 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8451 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8452 8453
8454 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8455 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8456 8457 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8458 """ 8459 8460 # Reset. 8461 self.interpreter.reset() 8462 8463 # Create the data pipe and load the base data. 8464 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8465 self.interpreter.state.load(data_path+sep+'r2eff_values') 8466 8467 # The model data pipe. 8468 model = 'NS MMQ 2-site' 8469 pipe_name = "%s - relax_disp" % model 8470 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8471 self.interpreter.pipe.switch(pipe_name=pipe_name) 8472 8473 # Set the model. 8474 self.interpreter.relax_disp.select_model(model=model) 8475 8476 # Cluster everything. 8477 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8478 8479 # Copy the data. 8480 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8481 8482 # Alias the spins. 8483 spin135S = cdp.mol[0].res[0].spin[0] 8484 spin135F = cdp.mol[0].res[0].spin[1] 8485 spin137S = cdp.mol[0].res[1].spin[0] 8486 spin137F = cdp.mol[0].res[1].spin[1] 8487 8488 # The R20 keys. 8489 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8490 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8491 8492 # Set the cluster specific parameters (only for the first spin). 8493 spin135S.pA = 0.847378444499757 8494 spin135S.kex = 264.055604934724329 8495 8496 # Set the initial parameter values. 8497 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8498 spin135S.dw = 0.585574008745351 8499 spin135S.dwH = 0.000000000000002 8500 8501 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8502 spin135F.dw = 0.856699277665748 8503 spin135F.dwH = 0.000000000582587 8504 8505 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8506 spin137S.dw = 0.772904450844973 8507 spin137S.dwH = 0.183351478512970 8508 8509 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8510 spin137F.dw = 0.984568590342831 8511 spin137F.dwH = 0.000000001993458 8512 8513 # Low precision optimisation. 8514 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8515 8516 # Printout. 8517 print("\n\nOptimised parameters:\n") 8518 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8519 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8520 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8521 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8522 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8523 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8524 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8525 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8526 8527 # FIXME: Remove this temporary return and properly check the results. 8528 return 8529 8530 # Checks for residue :135S. 8531 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8532 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8533 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8534 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8535 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8536 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8537 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8538 8539 # Checks for residue :135F. 8540 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8541 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8542 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8543 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8544 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8545 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8546 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8547 8548 # Checks for residue :137S. 8549 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8550 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8551 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8552 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8553 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8554 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8555 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8556 8557 # Checks for residue :137F. 8558 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8559 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8560 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8561 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8562 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8563 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8564 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8565 8566
8567 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8568 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8569 8570 # Setup the data. 8571 self.setup_tp02_data_to_ns_r1rho_2site() 8572 8573 # Alias the spins. 8574 spin1 = cdp.mol[0].res[0].spin[0] 8575 spin2 = cdp.mol[0].res[1].spin[0] 8576 8577 # The R20 keys. 8578 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8579 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8580 8581 # Checks for residue :1. 8582 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8583 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8584 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8585 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8586 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8587 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8588 8589 # Checks for residue :2. 8590 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8591 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8592 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8593 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8594 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8595 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8596 8597
8598 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8599 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8600 8601 # Setup the data. 8602 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8603 8604 # Alias the spins. 8605 spin1 = cdp.mol[0].res[0].spin[0] 8606 spin2 = cdp.mol[0].res[1].spin[0] 8607 8608 # The R20 keys. 8609 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8610 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8611 8612 # Checks for residue :1. 8613 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8614 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8615 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8616 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8617 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8618 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8619 8620 # Checks for residue :2. 8621 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8622 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8623 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8624 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8625 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8626 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8627 8628
8629 - def test_tp02_data_to_mp05(self):
8630 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8631 8632 # Fixed time variable and the models. 8633 ds.fixed = True 8634 ds.models = ['R2eff', 'MP05'] 8635 8636 # Execute the script. 8637 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8638 8639 # Switch back to the data pipe for the optimisation. 8640 self.interpreter.pipe.switch('MP05 - relax_disp') 8641 8642 # The equivalent MP05 parameters. 8643 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8644 pA = [0.775055484521586, 0.500000000036595] 8645 kex = [1235.20361276079, 2378.31403454691] 8646 delta_omega = [7.08194146569694, 5.4083562844306] 8647 chi2 = [0.0370400968727768, 0.182141732163934] 8648 8649 # Alias the spins. 8650 spin1 = cdp.mol[0].res[0].spin[0] 8651 spin2 = cdp.mol[0].res[1].spin[0] 8652 8653 # The R20 keys. 8654 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8655 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8656 8657 # Printout. 8658 print("\n\nOptimised parameters:\n") 8659 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8660 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8661 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8662 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8663 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8664 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8665 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8666 8667 # Check each spin. 8668 spin_index = 0 8669 for spin, spin_id in spin_loop(return_id=True): 8670 # Printout. 8671 print("\nSpin %s." % spin_id) 8672 8673 # Check the fitted parameters. 8674 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8675 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8676 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8677 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8678 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8679 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8680 8681 # Increment the spin index. 8682 spin_index += 1
8683 8684
8685 - def test_tp02_data_to_tap03(self):
8686 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8687 8688 # Fixed time variable and the models. 8689 ds.fixed = True 8690 ds.models = ['R2eff', 'TAP03'] 8691 8692 # Execute the script. 8693 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8694 8695 # Switch back to the data pipe for the optimisation. 8696 self.interpreter.pipe.switch('TAP03 - relax_disp') 8697 8698 # The equivalent TAP03 parameters. 8699 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8700 pA = [0.775042569092891, 0.500000000229685] 8701 kex = [1235.20852748765, 2379.47085580169] 8702 delta_omega = [7.08176806468445, 5.40708372863538] 8703 chi2 = [0.0371366837083293, 0.182212857256044] 8704 8705 # Alias the spins. 8706 spin1 = cdp.mol[0].res[0].spin[0] 8707 spin2 = cdp.mol[0].res[1].spin[0] 8708 8709 # The R20 keys. 8710 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8711 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8712 8713 # Printout. 8714 print("\n\nOptimised parameters:\n") 8715 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8716 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8717 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8718 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8719 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8720 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8721 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8722 8723 # Switch to the 'MP05' model data pipe, then check for each spin. 8724 self.interpreter.pipe.switch('TAP03 - relax_disp') 8725 spin_index = 0 8726 for spin, spin_id in spin_loop(return_id=True): 8727 # Printout. 8728 print("\nSpin %s." % spin_id) 8729 8730 # Check the fitted parameters. 8731 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8732 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8733 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8734 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8735 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8736 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8737 8738 # Increment the spin index. 8739 spin_index += 1
8740 8741
8743 """Implementation of Task #7882 U{https://gna.org/task/?7882}: Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals""" 8744 8745 # First check that results are stored with minimisation, to make sure that Sum of Squares are stored (Chi2 without weighting) and degrees of freedom (dof) is stored. 8746 8747 # Load the results file from a clustered minimisation. 8748 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8749 self.interpreter.results.read(file_name) 8750 8751 # Get the spins, which was used for clustering. 8752 spins_cluster = cdp.clustering['sel'] 8753 spins_free = cdp.clustering['free spins'] 8754 8755 # For sanity check, calculate degree of freedom. 8756 cur_spin_id = spins_cluster[0] 8757 cur_spin = return_spin(cur_spin_id) 8758 8759 # Calculate total number of datapoins. 8760 N = len(spins_cluster) 8761 N_dp = N * len(cur_spin.r2eff) 8762 8763 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8764 N_par = cdp.spectrometer_frq_count * N + N + 1 + 1 8765 dof = N_dp - N_par 8766 8767 # Sanity check of parameters. 8768 print(N_par, N_dp) 8769 8770 # Number of MC 8771 mc_nr = 3 8772 8773 # Setup MC for errors generated from the distribution described by chi2 and degrees of freedom from best fit. 8774 self.interpreter.monte_carlo.setup(number=mc_nr) 8775 8776 # Create data. 8777 self.interpreter.monte_carlo.create_data(distribution="red_chi2") 8778 8779 # Setup MC again. 8780 self.interpreter.monte_carlo.setup(number=mc_nr) 8781 8782 # Create data, and set the fixed error value, without setting the correct distribution. 8783 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, fixed_error=1.) 8784 8785 # Setup MC again. 8786 self.interpreter.monte_carlo.setup(number=mc_nr) 8787 8788 # Create data, with fixed error distribution, but not setting the error value. 8789 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="fixed") 8790 8791 # Setup MC again. 8792 self.interpreter.monte_carlo.create_data(distribution="fixed", fixed_error=1.) 8793 8794 # Now select the R2eff model, and try again. Expect raising an error. 8795 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8796 8797 # Setup MC again. 8798 self.interpreter.monte_carlo.setup(number=mc_nr) 8799 8800 # Create data, and assert failure. 8801 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="red_chi2") 8802 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, method="direct", distribution="red_chi2")
8803 8804
8805 - def x_test_task_7882_kex_conf(self):
8806 """Test related to Task #7882 U{https://gna.org/task/?7882}: Try making a confidence interval of kex. 8807 According to the regression book of Graphpad: U{http://www.graphpad.com/faq/file/Prism4RegressionBook.pdf}. 8808 Page 109-111. 8809 """ 8810 8811 # Load the results file from a clustered minimisation. 8812 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8813 self.interpreter.results.read(file_name) 8814 8815 # Get the spins, which was used for clustering. 8816 spins_cluster = cdp.clustering['sel'] 8817 spins_free = cdp.clustering['free spins'] 8818 8819 # For sanity check, calculate degree of freedom. 8820 cur_spin_id = spins_cluster[0] 8821 cur_spin = return_spin(cur_spin_id) 8822 8823 # Calculate total number of datapoins. 8824 Ns = len(spins_cluster) 8825 N_dp = Ns * len(cur_spin.r2eff) 8826 8827 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8828 N_par = cdp.spectrometer_frq_count * Ns + Ns + 1 + 1 8829 dof_fit = N_dp - N_par 8830 8831 # Assert values. 8832 self.assertEqual(Ns, 61) 8833 self.assertEqual(N_dp, 1952) 8834 self.assertEqual(N_par, 185) 8835 8836 # Confidence interval of kex. 8837 # The number of parameters to check is kex = 1. 8838 P = 1 8839 # Number of datapoints 8840 N = N_dp 8841 # The degrees of freedom for this confidence interval 8842 dof_conf = N - P 8843 8844 # The critical value of the F distribution with p-value of 0.05 for 95% confidence. 8845 # Can be calculated with microsoft excel: 8846 # F=FINV(0,05; P; dof_conf), F=FINV(0,05; P; dof_conf), F=FINV(0,05; 1; 1951)=3,846229551 8847 # Can also be calculated with: import scipy.stats; scipy.stats.f.isf(0.05, 1, 1951)=3.8462295505435562 8848 F = 3.8462295505435562 8849 # Then calculate the scaling of chi2, which is the weighted sum of squares of best fit. 8850 scale = F*P/dof_conf +1 8851 8852 # Get the sum of best fit. 8853 SSbest_fit = cur_spin.chi2 8854 SSbest_kex = cur_spin.kex 8855 8856 # Get the scaled sum of best fit 8857 SSall_fixed = SSbest_fit * scale 8858 8859 print(SSbest_fit, scale, SSall_fixed) 8860 8861 # Now generate a list of kex values to try. 8862 kex_cur = cur_spin.kex 8863 kex_list = linspace(kex_cur - 1500, kex_cur + 3000, 200) 8864 8865 chi2_list = [] 8866 8867 for kex in kex_list: 8868 self.interpreter.value.set(val=kex, param='kex') 8869 8870 # Calculate the chi2 values. 8871 self.interpreter.minimise.calculate(verbosity=0) 8872 8873 # Get the chi2 value 8874 chi2_cur = cur_spin.chi2 8875 print("kex=%3.2f, chi2=%3.2f"%(kex, chi2_cur), chi2_cur<SSall_fixed) 8876 8877 # Add to list 8878 chi2_list.append(chi2_cur) 8879 8880 # Now make to numpy array. 8881 chi2_list = asarray(chi2_list) 8882 8883 # Now make a selection mask based on the criteria. 8884 sel_mask = chi2_list < SSall_fixed 8885 8886 # Select values of kex, and chi2_list 8887 kex_sel = kex_list[sel_mask] 8888 chi2_sel = chi2_list[sel_mask] 8889 8890 # Now make plot 8891 print(SSbest_kex, SSbest_fit, SSall_fixed) 8892 print(kex_sel) 8893 print(chi2_sel) 8894 8895 if True: 8896 import matplotlib.pyplot as plt 8897 8898 plt.plot(kex_sel, chi2_sel, "bo") 8899 plt.plot(SSbest_kex, SSbest_fit, "g*") 8900 plt.show()
8901 8902
8903 - def test_tp02_data_to_tp02(self):
8904 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8905 8906 # Fixed time variable. 8907 ds.fixed = True 8908 8909 # Execute the script. 8910 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8911 8912 # The original parameters. 8913 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8914 pA = 0.7654321 8915 kex = 1234.56789 8916 delta_omega = [7.0, 9.0] 8917 8918 # The R20 keys. 8919 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8920 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8921 8922 # Switch to the 'TP02' model data pipe, then check for each spin. 8923 self.interpreter.pipe.switch('TP02 - relax_disp') 8924 spin_index = 0 8925 for spin, spin_id in spin_loop(return_id=True): 8926 # Printout. 8927 print("\nSpin %s." % spin_id) 8928 8929 # Check the fitted parameters. 8930 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8931 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8932 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8933 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8934 8935 # Increment the spin index. 8936 spin_index += 1
8937 8938
8940 """System test of the value.write function to write intensities for an R1rho setup. 8941 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8942 8943 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8944 """ 8945 8946 # Load the state. 8947 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8948 self.interpreter.state.load(statefile, force=True) 8949 8950 # Set filepaths. 8951 int_filepath = ds.tmpdir+sep+'int.out' 8952 8953 # Write out the intensity parameter file. 8954 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8955 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8956 8957 # Test the file exists. 8958 self.assert_(access(int_filepath, F_OK)) 8959 8960 # Open the files for testing. 8961 int_file = open(int_filepath, 'r') 8962 8963 # Loop over the intensity file to test values. 8964 for line in int_file: 8965 # Skip lines starting with #. 8966 if line[0] == "#": 8967 continue 8968 8969 # Split the line 8970 linesplit = line.split() 8971 8972 # Assume values 8973 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8974 self.assertEqual(linesplit[5], "115571.4") 8975 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8976 self.assertEqual(linesplit[5], "68377.52") 8977 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8978 self.assertEqual(linesplit[5], "9141.689") 8979 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8980 self.assertEqual(linesplit[5], "29123.77") 8981 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8982 self.assertEqual(linesplit[5], "58914.94") 8983 8984 # Close files 8985 int_file.close()
8986 8987
8989 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8990 8991 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8992 """ 8993 8994 # Load the state. 8995 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8996 self.interpreter.state.load(statefile, force=True) 8997 8998 # Set filepaths. 8999 theta_filepath = ds.tmpdir+sep+'theta.out' 9000 9001 # Write out the theta parameter file. 9002 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 9003 9004 # Test the file exists. 9005 self.assert_(access(theta_filepath, F_OK)) 9006 9007 # Open the files for testing. 9008 theta_file = open(theta_filepath, 'r') 9009 9010 # Loop over the theta file to test values. 9011 for line in theta_file: 9012 # Skip lines starting with #. 9013 if line[0] == "#": 9014 continue 9015 # Print lines, not including newline character. 9016 print(line[:-1]) 9017 9018 # Split the line 9019 linesplit = line.split() 9020 9021 # Assume values 9022 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 9023 self.assertNotEqual(linesplit[5], "None") 9024 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 9025 self.assertNotEqual(linesplit[5], "None") 9026 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 9027 self.assertNotEqual(linesplit[5], "None") 9028 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 9029 self.assertNotEqual(linesplit[5], "None") 9030 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 9031 self.assertNotEqual(linesplit[5], "None") 9032 9033 # Close files 9034 theta_file.close()
9035 9036
9038 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 9039 9040 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 9041 """ 9042 9043 # Load the state. 9044 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 9045 self.interpreter.state.load(statefile, force=True) 9046 9047 # Set filepaths. 9048 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 9049 9050 # Write out the w_eff parameter file. 9051 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 9052 9053 # Test the file exists. 9054 self.assert_(access(w_eff_filepath, F_OK)) 9055 9056 # Open the files for testing. 9057 w_eff_file = open(w_eff_filepath, 'r') 9058 9059 # Loop over the w_eff file to test values. 9060 for line in w_eff_file: 9061 # Skip lines starting with #. 9062 if line[0] == "#": 9063 continue 9064 # Print lines, not including newline character. 9065 print(line[:-1]) 9066 9067 # Split the line 9068 linesplit = line.split() 9069 9070 # Assume values 9071 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 9072 self.assertNotEqual(linesplit[5], "None") 9073 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 9074 self.assertNotEqual(linesplit[5], "None") 9075 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 9076 self.assertNotEqual(linesplit[5], "None") 9077 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 9078 self.assertNotEqual(linesplit[5], "None") 9079 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 9080 self.assertNotEqual(linesplit[5], "None") 9081 9082 # Close files 9083 w_eff_file.close()
9084 9085
9087 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 9088 9089 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 9090 """ 9091 9092 # Load the state. 9093 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 9094 self.interpreter.state.load(statefile, force=True) 9095 9096 # Set pipe name, bundle and type. 9097 pipe_name = 'base pipe' 9098 pipe_bundle = 'relax_disp' 9099 pipe_type = 'relax_disp' 9100 9101 # The path to the data files. 9102 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 9103 9104 # Deselect all spins 9105 self.interpreter.deselect.all() 9106 9107 # Specify spins to be selected. 9108 select_spin_ids = [ 9109 ":13@N", 9110 ":15@N", 9111 ":16@N", 9112 ":25@N", 9113 ":26@N", 9114 ":28@N", 9115 ":39@N", 9116 ":40@N", 9117 ":41@N", 9118 ":43@N", 9119 ":44@N", 9120 ":45@N", 9121 ":49@N", 9122 ":52@N", 9123 ":53@N"] 9124 9125 # Reverse the selection for the spins. 9126 for curspin in select_spin_ids: 9127 print("Selecting spin %s"%curspin) 9128 self.interpreter.deselect.reverse(spin_id=curspin) 9129 9130 # Read the R1 data 9131 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 9132 9133 # The dispersion models. 9134 MODELS = ['R2eff'] 9135 9136 # The grid search size (the number of increments per dimension). 9137 GRID_INC = 4 9138 9139 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 9140 MC_NUM = 3 9141 9142 # Model selection technique. 9143 MODSEL = 'AIC' 9144 9145 # Execute the auto-analysis (fast). 9146 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 9147 OPT_FUNC_TOL = 1e-1 9148 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 9149 OPT_MAX_ITERATIONS = 1000 9150 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 9151 9152 # Run the analysis. 9153 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 9154 9155 ## Check for file creation 9156 # Set filepaths. 9157 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 9158 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 9159 9160 # Test the files exists. 9161 self.assert_(access(theta_filepath, F_OK)) 9162 self.assert_(access(w_eff_filepath, F_OK)) 9163 9164 # Open the files for testing. 9165 theta_file = open(theta_filepath, 'r') 9166 theta_result = [ 9167 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 9168 "#\n", 9169 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9170 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9171 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9172 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9173 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9174 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9175 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9176 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9177 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 9178 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9179 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 9180 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 9181 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9182 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9183 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9184 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9185 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9186 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 9187 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 9188 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9189 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 9190 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9191 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9192 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9193 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9194 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9195 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9196 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9197 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9198 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9199 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 9200 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 9201 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 9202 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9203 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 9204 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 9205 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 9206 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9207 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9208 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 9209 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9210 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9211 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 9212 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 9213 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9214 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9215 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9216 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9217 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9218 ] 9219 # Check the created theta file. 9220 lines = theta_file.readlines() 9221 for i in range(len(lines)): 9222 # Test lines starting with # 9223 if theta_result[i][0] == "#": 9224 self.assertEqual(theta_result[i], lines[i]) 9225 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9226 if theta_result[i] == lines[i]: 9227 self.assertEqual(theta_result[i], lines[i]) 9228 # If the line is not equal each other, make a slower comparison of values. 9229 else: 9230 # Print lines if they don't match. To help find differences. 9231 print(theta_result[i]) 9232 print(lines[i]) 9233 9234 # First test first 62 characters containing spin information 9235 self.assertEqual(theta_result[i][:62], lines[i][:62]) 9236 9237 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9238 theta_result_s = theta_result[i][62:].split()[::2] 9239 print(theta_result_s ) 9240 lines_s = lines[i][62:].split()[::2] 9241 print(lines_s) 9242 # Loop over the value elements 9243 for j in range(len(lines_s)): 9244 print(theta_result_s[j], lines_s[j]) 9245 # Assume a precision to digits. 9246 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 9247 9248 # Close file 9249 theta_file.close() 9250 9251 w_eff_file = open(w_eff_filepath, 'r') 9252 w_eff_result = [ 9253 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 9254 "#\n", 9255 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9256 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9257 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9258 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9259 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9260 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9261 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9262 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9263 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 9264 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9265 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 9266 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 9267 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9268 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9269 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9270 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9271 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9272 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 9273 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 9274 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9275 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 9276 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9277 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9278 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9279 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9280 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9281 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9282 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9283 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9284 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9285 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 9286 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 9287 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 9288 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9289 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 9290 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 9291 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 9292 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9293 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9294 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 9295 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9296 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9297 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 9298 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 9299 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9300 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9301 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9302 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9303 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9304 ] 9305 # Check the created w_eff file. 9306 lines = w_eff_file.readlines() 9307 for i in range(len(lines)): 9308 # Test lines starting with # 9309 if w_eff_result[i][0] == "#": 9310 self.assertEqual(w_eff_result[i], lines[i]) 9311 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9312 if w_eff_result[i] == lines[i]: 9313 self.assertEqual(w_eff_result[i], lines[i]) 9314 # If the line is not equal each other, make a slower comparison of values. 9315 else: 9316 # Print lines if they don't match. To help find differences. 9317 print(w_eff_result[i]) 9318 print(lines[i]) 9319 9320 # First test first 62 characters containing spin information 9321 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 9322 9323 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9324 w_eff_result_s = w_eff_result[i][62:].split()[::2] 9325 print(w_eff_result_s ) 9326 lines_s = lines[i][62:].split()[::2] 9327 print(lines_s) 9328 # Loop over the value elements 9329 for j in range(len(lines_s)): 9330 print(w_eff_result_s[j], lines_s[j]) 9331 # Assume a precision to digits. 9332 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 9333 9334 # Close file 9335 w_eff_file.close()
9336 9337
9339 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 9340 9341 This follows Task 7822. 9342 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 9343 9344 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 9345 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 9346 """ 9347 9348 # Load the data. 9349 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 9350 9351 # Set pipe name, bundle and type. 9352 pipe_name = 'base pipe' 9353 pipe_bundle = 'relax_disp' 9354 pipe_type = 'relax_disp' 9355 9356 # Create the data pipe. 9357 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 9358 9359 file = data_path + '1_setup_r1rho_GUI.py' 9360 self.interpreter.script(file=file, dir=None) 9361 9362 # Deselect all spins. 9363 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 9364 9365 # Select one spin. 9366 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 9367 9368 # Set the model. 9369 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 9370 9371 # Check if intensity errors have already been calculated. 9372 check_intensity_errors() 9373 9374 # Do a grid search. 9375 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 9376 9377 # Set algorithm. 9378 min_algor = 'Newton' 9379 constraints = True 9380 if constraints: 9381 min_options = ('%s'%(min_algor),) 9382 #min_algor = 'Log barrier' 9383 min_algor = 'Method of Multipliers' 9384 scaling_matrix = assemble_scaling_matrix(scaling=True) 9385 9386 # Collect spins 9387 all_spin_ids = [] 9388 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9389 all_spin_ids.append(spin_id) 9390 9391 spins = spin_ids_to_containers(all_spin_ids[:1]) 9392 9393 # Get constraints 9394 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 9395 else: 9396 min_options = () 9397 A, b = None, None 9398 min_options = () 9399 sim_boot = 200 9400 scaling_list = [1.0, 1.0] 9401 9402 # Minimise. 9403 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 9404 9405 # Loop over old err attributes. 9406 err_attr_list = ['r2eff_err', 'i0_err'] 9407 9408 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9409 # Loop over old err attributes. 9410 for err_attr in err_attr_list: 9411 if hasattr(cur_spin, err_attr): 9412 delattr(cur_spin, err_attr) 9413 9414 # Collect the estimation data from boot. 9415 my_dic = {} 9416 param_key_list = [] 9417 est_keys = [] 9418 est_key = '-2' 9419 est_keys.append(est_key) 9420 spin_id_list = [] 9421 9422 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9423 # Add key to dic. 9424 my_dic[spin_id] = {} 9425 9426 # Add key for estimate. 9427 my_dic[spin_id][est_key] = {} 9428 9429 # Add spin key to list. 9430 spin_id_list.append(spin_id) 9431 9432 # Generate spin string. 9433 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9434 9435 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9436 # Generate the param_key. 9437 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9438 9439 # Append key. 9440 param_key_list.append(param_key) 9441 9442 # Add key to dic. 9443 my_dic[spin_id][est_key][param_key] = {} 9444 9445 values = [] 9446 errors = [] 9447 times = [] 9448 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9449 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9450 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9451 times.append(time) 9452 9453 # Convert to numpy array. 9454 values = asarray(values) 9455 errors = asarray(errors) 9456 times = asarray(times) 9457 9458 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9459 i0 = getattr(cur_spin, 'i0')[param_key] 9460 9461 R_m_sim_l = [] 9462 I0_m_sim_l = [] 9463 for j in range(sim_boot): 9464 if j in range(0, 100000, 100): 9465 print("Simulation %i"%j) 9466 # Start minimisation. 9467 9468 # Produce errors 9469 I_err = [] 9470 for j, error in enumerate(errors): 9471 I_error = gauss(values[j], error) 9472 I_err.append(I_error) 9473 # Convert to numpy array. 9474 I_err = asarray(I_err) 9475 9476 x0 = [r2eff, i0] 9477 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 9478 9479 # Ref input. 9480 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 9481 # l=l, u=u, c=c, dc=dc, d2c=d2c 9482 # l: Lower bound constraint vector (l <= x <= u). 9483 # u: Upper bound constraint vector (l <= x <= u). 9484 # c: User supplied constraint function. 9485 # dc: User supplied constraint gradient function. 9486 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 9487 9488 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9489 R_m_sim_l.append(R_m_sim_j) 9490 I0_m_sim_l.append(I0_m_sim_j) 9491 9492 # Get stats on distribution. 9493 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9494 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9495 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9496 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9497 9498 # Estimate R2eff errors. 9499 self.interpreter.relax_disp.r2eff_err_estimate() 9500 9501 est_key = '-1' 9502 est_keys.append(est_key) 9503 9504 # Collect data. 9505 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9506 # Add key for estimate. 9507 my_dic[spin_id][est_key] = {} 9508 9509 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9510 # Generate the param_key. 9511 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9512 9513 # Add key to dic. 9514 my_dic[spin_id][est_key][param_key] = {} 9515 9516 # Get the value. 9517 # Loop over err attributes. 9518 for err_attr in err_attr_list: 9519 if hasattr(cur_spin, err_attr): 9520 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9521 else: 9522 get_err_attr = 0.0 9523 9524 # Save to dic. 9525 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9526 9527 9528 # Make Carlo Simulations number 9529 mc_number_list = list(range(0, 1000, 250)) 9530 9531 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 9532 9533 # Loop over the Monte Carlo simulations: 9534 for number in mc_number_list: 9535 # First delete old simulations. 9536 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9537 # Loop over old err attributes. 9538 for err_attr in err_attr_list: 9539 if hasattr(cur_spin, err_attr): 9540 delattr(cur_spin, err_attr) 9541 9542 # Loop over the simulated attributes. 9543 for sim_attr in sim_attr_list: 9544 if hasattr(cur_spin, sim_attr): 9545 delattr(cur_spin, sim_attr) 9546 9547 self.interpreter.monte_carlo.setup(number=number) 9548 self.interpreter.monte_carlo.create_data() 9549 self.interpreter.monte_carlo.initial_values() 9550 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9551 self.interpreter.eliminate() 9552 self.interpreter.monte_carlo.error_analysis() 9553 9554 est_key = '%i'%number 9555 est_keys.append(est_key) 9556 9557 # Collect data. 9558 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9559 # Add key for estimate. 9560 my_dic[spin_id][est_key] = {} 9561 9562 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9563 # Generate the param_key. 9564 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9565 9566 # Add key to dic. 9567 my_dic[spin_id][est_key][param_key] = {} 9568 9569 # Get the value. 9570 # Loop over err attributes. 9571 for err_attr in err_attr_list: 9572 if hasattr(cur_spin, err_attr): 9573 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9574 else: 9575 get_err_attr = 0.0 9576 9577 # Save to dic. 9578 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9579 9580 # Set what to extract. 9581 err_attr = err_attr_list[0] 9582 9583 # Define list with text. 9584 text_list = [] 9585 9586 # Now loop through the data. 9587 for spin_id in spin_id_list: 9588 for est_key in est_keys: 9589 # Define list to pickup data. 9590 r2eff_err_list = [] 9591 9592 for param_key in param_key_list: 9593 # Get the value. 9594 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9595 9596 # Add to list. 9597 r2eff_err_list.append(r2eff_err) 9598 9599 # Sum the list 9600 sum_array = sum(array(r2eff_err_list)) 9601 9602 # Join floats to string. 9603 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9604 9605 # Define print string. 9606 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9607 text_list.append(text) 9608 9609 9610 # Now print. 9611 filepath = NamedTemporaryFile(delete=False).name 9612 # Open the files for testing. 9613 w_file = open(filepath, 'w') 9614 9615 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9616 9617 for text in text_list: 9618 # Print. 9619 print(text) 9620 9621 # Write to file. 9622 w_file.write(text+"\n") 9623 9624 # Close files 9625 w_file.close() 9626 9627 print("Filepath is: %s"%filepath) 9628 print("Start 'gnuplot' and write:") 9629 print("set term dumb") 9630 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9631 9632
9633 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9634 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9635 9636 # Check the kex value of residue 52 9637 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9638 9639 # Print results for each model. 9640 print("\n\n################") 9641 print("Printing results") 9642 print("################\n") 9643 for model in models: 9644 # Skip R2eff model. 9645 if model == MODEL_R2EFF: 9646 continue 9647 9648 # Switch to pipe. 9649 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9650 print("\nModel: %s" % (model)) 9651 9652 # Loop over the spins. 9653 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9654 # Generate spin string. 9655 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9656 9657 # Loop over the parameters. 9658 print("Optimised parameters for spin: %s" % (spin_string)) 9659 for param in cur_spin.params + ['chi2']: 9660 # Get the value. 9661 if param in ['r1', 'r2']: 9662 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9663 # Generate the R20 key. 9664 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9665 9666 # Get the value. 9667 value = getattr(cur_spin, param)[r20_key] 9668 9669 # Print value. 9670 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9671 9672 # Compare values. 9673 if spin_id == ':52@N': 9674 if param == 'r1': 9675 if model == MODEL_NOREX: 9676 if r2eff_estimate == 'direct': 9677 self.assertAlmostEqual(value, 1.46138805) 9678 elif r2eff_estimate == 'MC2000': 9679 self.assertAlmostEqual(value, 1.46328102) 9680 elif r2eff_estimate == 'chi2_pyt': 9681 self.assertAlmostEqual(value, 1.43820629) 9682 elif model == MODEL_DPL94: 9683 if r2eff_estimate == 'direct': 9684 self.assertAlmostEqual(value, 1.44845742) 9685 elif r2eff_estimate == 'MC2000': 9686 self.assertAlmostEqual(value, 1.45019848) 9687 elif r2eff_estimate == 'chi2_pyt': 9688 self.assertAlmostEqual(value, 1.44666512) 9689 elif model == MODEL_TP02: 9690 if r2eff_estimate == 'direct': 9691 self.assertAlmostEqual(value, 1.54354392) 9692 elif r2eff_estimate == 'MC2000': 9693 self.assertAlmostEqual(value, 1.54352369) 9694 elif r2eff_estimate == 'chi2_pyt': 9695 self.assertAlmostEqual(value, 1.55964020) 9696 elif model == MODEL_TAP03: 9697 if r2eff_estimate == 'direct': 9698 self.assertAlmostEqual(value, 1.54356410) 9699 elif r2eff_estimate == 'MC2000': 9700 self.assertAlmostEqual(value, 1.54354367) 9701 elif r2eff_estimate == 'chi2_pyt': 9702 self.assertAlmostEqual(value, 1.55967157) 9703 elif model == MODEL_MP05: 9704 if r2eff_estimate == 'direct': 9705 self.assertAlmostEqual(value, 1.54356416) 9706 elif r2eff_estimate == 'MC2000': 9707 self.assertAlmostEqual(value, 1.54354372) 9708 elif r2eff_estimate == 'chi2_pyt': 9709 self.assertAlmostEqual(value, 1.55967163) 9710 elif model == MODEL_NS_R1RHO_2SITE: 9711 if r2eff_estimate == 'direct': 9712 self.assertAlmostEqual(value, 1.41359221, 5) 9713 elif r2eff_estimate == 'MC2000': 9714 self.assertAlmostEqual(value, 1.41321968, 5) 9715 elif r2eff_estimate == 'chi2_pyt': 9716 self.assertAlmostEqual(value, 1.36303129, 5) 9717 9718 elif param == 'r2': 9719 if model == MODEL_NOREX: 9720 if r2eff_estimate == 'direct': 9721 self.assertAlmostEqual(value, 11.48392439) 9722 elif r2eff_estimate == 'MC2000': 9723 self.assertAlmostEqual(value, 11.48040934) 9724 elif r2eff_estimate == 'chi2_pyt': 9725 self.assertAlmostEqual(value, 11.47224488) 9726 elif model == MODEL_DPL94: 9727 if r2eff_estimate == 'direct': 9728 self.assertAlmostEqual(value, 10.15688372, 6) 9729 elif r2eff_estimate == 'MC2000': 9730 self.assertAlmostEqual(value, 10.16304887, 6) 9731 elif r2eff_estimate == 'chi2_pyt': 9732 self.assertAlmostEqual(value, 9.20037797, 6) 9733 elif model == MODEL_TP02: 9734 if r2eff_estimate == 'direct': 9735 self.assertAlmostEqual(value, 9.72654896, 6) 9736 elif r2eff_estimate == 'MC2000': 9737 self.assertAlmostEqual(value, 9.72772726, 6) 9738 elif r2eff_estimate == 'chi2_pyt': 9739 self.assertAlmostEqual(value, 9.53948340, 6) 9740 elif model == MODEL_TAP03: 9741 if r2eff_estimate == 'direct': 9742 self.assertAlmostEqual(value, 9.72641887, 6) 9743 elif r2eff_estimate == 'MC2000': 9744 self.assertAlmostEqual(value, 9.72759374, 6) 9745 elif r2eff_estimate == 'chi2_pyt': 9746 self.assertAlmostEqual(value, 9.53926913, 6) 9747 elif model == MODEL_MP05: 9748 if r2eff_estimate == 'direct': 9749 self.assertAlmostEqual(value, 9.72641723, 6) 9750 elif r2eff_estimate == 'MC2000': 9751 self.assertAlmostEqual(value, 9.72759220, 6) 9752 elif r2eff_estimate == 'chi2_pyt': 9753 self.assertAlmostEqual(value, 9.53926778, 6) 9754 elif model == MODEL_NS_R1RHO_2SITE: 9755 if r2eff_estimate == 'direct': 9756 self.assertAlmostEqual(value, 9.34531535, 5) 9757 elif r2eff_estimate == 'MC2000': 9758 self.assertAlmostEqual(value, 9.34602793, 5) 9759 elif r2eff_estimate == 'chi2_pyt': 9760 self.assertAlmostEqual(value, 9.17631409, 5) 9761 9762 # For all other parameters. 9763 else: 9764 # Get the value. 9765 value = getattr(cur_spin, param) 9766 9767 # Print value. 9768 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9769 9770 # Compare values. 9771 if spin_id == ':52@N': 9772 if param == 'phi_ex': 9773 if model == MODEL_DPL94: 9774 if r2eff_estimate == 'direct': 9775 self.assertAlmostEqual(value, 0.07599563) 9776 elif r2eff_estimate == 'MC2000': 9777 self.assertAlmostEqual(value, 0.07561937) 9778 elif r2eff_estimate == 'chi2_pyt': 9779 self.assertAlmostEqual(value, 0.12946061) 9780 9781 elif param == 'pA': 9782 if model == MODEL_TP02: 9783 if r2eff_estimate == 'direct': 9784 self.assertAlmostEqual(value, 0.88827040) 9785 elif r2eff_estimate == 'MC2000': 9786 self.assertAlmostEqual(value, 0.88807487) 9787 elif r2eff_estimate == 'chi2_pyt': 9788 self.assertAlmostEqual(value, 0.87746233) 9789 elif model == MODEL_TAP03: 9790 if r2eff_estimate == 'direct': 9791 self.assertAlmostEqual(value, 0.88828922) 9792 elif r2eff_estimate == 'MC2000': 9793 self.assertAlmostEqual(value, 0.88809318) 9794 elif r2eff_estimate == 'chi2_pyt': 9795 self.assertAlmostEqual(value, 0.87747558) 9796 elif model == MODEL_MP05: 9797 if r2eff_estimate == 'direct': 9798 self.assertAlmostEqual(value, 0.88828924, 6) 9799 elif r2eff_estimate == 'MC2000': 9800 self.assertAlmostEqual(value, 0.88809321) 9801 elif r2eff_estimate == 'chi2_pyt': 9802 self.assertAlmostEqual(value, 0.87747562) 9803 elif model == MODEL_NS_R1RHO_2SITE: 9804 if r2eff_estimate == 'direct': 9805 self.assertAlmostEqual(value, 0.94504369, 6) 9806 elif r2eff_estimate == 'MC2000': 9807 self.assertAlmostEqual(value, 0.94496541, 6) 9808 elif r2eff_estimate == 'chi2_pyt': 9809 self.assertAlmostEqual(value, 0.92084707, 6) 9810 9811 elif param == 'dw': 9812 if model == MODEL_TP02: 9813 if r2eff_estimate == 'direct': 9814 self.assertAlmostEqual(value, 1.08875840, 6) 9815 elif r2eff_estimate == 'MC2000': 9816 self.assertAlmostEqual(value, 1.08765638, 6) 9817 elif r2eff_estimate == 'chi2_pyt': 9818 self.assertAlmostEqual(value, 1.09753230, 6) 9819 elif model == MODEL_TAP03: 9820 if r2eff_estimate == 'direct': 9821 self.assertAlmostEqual(value, 1.08837238, 6) 9822 elif r2eff_estimate == 'MC2000': 9823 self.assertAlmostEqual(value, 1.08726698, 6) 9824 elif r2eff_estimate == 'chi2_pyt': 9825 self.assertAlmostEqual(value, 1.09708821, 6) 9826 elif model == MODEL_MP05: 9827 if r2eff_estimate == 'direct': 9828 self.assertAlmostEqual(value, 1.08837241, 6) 9829 elif r2eff_estimate == 'MC2000': 9830 self.assertAlmostEqual(value, 1.08726706, 6) 9831 elif r2eff_estimate == 'chi2_pyt': 9832 self.assertAlmostEqual(value, 1.09708832, 6) 9833 elif model == MODEL_NS_R1RHO_2SITE: 9834 if r2eff_estimate == 'direct': 9835 self.assertAlmostEqual(value, 1.56001812, 5) 9836 elif r2eff_estimate == 'MC2000': 9837 self.assertAlmostEqual(value, 1.55833321, 5) 9838 elif r2eff_estimate == 'chi2_pyt': 9839 self.assertAlmostEqual(value, 1.36406712, 5) 9840 9841 elif param == 'kex': 9842 if model == MODEL_DPL94: 9843 if r2eff_estimate == 'direct': 9844 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9845 elif r2eff_estimate == 'MC2000': 9846 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9847 elif r2eff_estimate == 'chi2_pyt': 9848 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9849 elif model == MODEL_TP02: 9850 if r2eff_estimate == 'direct': 9851 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9852 elif r2eff_estimate == 'MC2000': 9853 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9854 elif r2eff_estimate == 'chi2_pyt': 9855 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9856 elif model == MODEL_TAP03: 9857 if r2eff_estimate == 'direct': 9858 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9859 elif r2eff_estimate == 'MC2000': 9860 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9861 elif r2eff_estimate == 'chi2_pyt': 9862 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9863 elif model == MODEL_MP05: 9864 if r2eff_estimate == 'direct': 9865 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9866 elif r2eff_estimate == 'MC2000': 9867 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9868 elif r2eff_estimate == 'chi2_pyt': 9869 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9870 elif model == MODEL_NS_R1RHO_2SITE: 9871 if r2eff_estimate == 'direct': 9872 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9873 elif r2eff_estimate == 'MC2000': 9874 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9875 elif r2eff_estimate == 'chi2_pyt': 9876 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9877 9878 elif param == 'chi2': 9879 if model == MODEL_NOREX: 9880 if r2eff_estimate == 'direct': 9881 self.assertAlmostEqual(value, 848.42016907, 5) 9882 elif r2eff_estimate == 'MC2000': 9883 self.assertAlmostEqual(value, 3363.95829122, 5) 9884 elif r2eff_estimate == 'chi2_pyt': 9885 self.assertAlmostEqual(value, 5976.49946726, 5) 9886 elif model == MODEL_DPL94: 9887 if r2eff_estimate == 'direct': 9888 self.assertAlmostEqual(value, 179.47041241) 9889 elif r2eff_estimate == 'MC2000': 9890 self.assertAlmostEqual(value, 710.24767560) 9891 elif r2eff_estimate == 'chi2_pyt': 9892 self.assertAlmostEqual(value, 612.72616697, 5) 9893 elif model == MODEL_TP02: 9894 if r2eff_estimate == 'direct': 9895 self.assertAlmostEqual(value, 29.33882530, 6) 9896 elif r2eff_estimate == 'MC2000': 9897 self.assertAlmostEqual(value, 114.47142772, 6) 9898 elif r2eff_estimate == 'chi2_pyt': 9899 self.assertAlmostEqual(value, 250.50838162, 5) 9900 elif model == MODEL_TAP03: 9901 if r2eff_estimate == 'direct': 9902 self.assertAlmostEqual(value, 29.29050673, 6) 9903 elif r2eff_estimate == 'MC2000': 9904 self.assertAlmostEqual(value, 114.27987534) 9905 elif r2eff_estimate == 'chi2_pyt': 9906 self.assertAlmostEqual(value, 250.04050719, 5) 9907 elif model == MODEL_MP05: 9908 if r2eff_estimate == 'direct': 9909 self.assertAlmostEqual(value, 29.29054301, 6) 9910 elif r2eff_estimate == 'MC2000': 9911 self.assertAlmostEqual(value, 114.28002272) 9912 elif r2eff_estimate == 'chi2_pyt': 9913 self.assertAlmostEqual(value, 250.04077478, 5) 9914 elif model == MODEL_NS_R1RHO_2SITE: 9915 if r2eff_estimate == 'direct': 9916 self.assertAlmostEqual(value, 34.44010543, 6) 9917 elif r2eff_estimate == 'MC2000': 9918 self.assertAlmostEqual(value, 134.14368365) 9919 elif r2eff_estimate == 'chi2_pyt': 9920 self.assertAlmostEqual(value, 278.55121388, 5) 9921 9922 9923 # Print the final pipe. 9924 model = 'final' 9925 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9926 print("\nFinal pipe") 9927 9928 # Loop over the spins. 9929 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9930 # Generate spin string. 9931 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9932 9933 # Loop over the parameters. 9934 print("Optimised model for spin: %s" % (spin_string)) 9935 param = 'model' 9936 9937 # Get the value. 9938 value = getattr(cur_spin, param) 9939 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9940 9941 9942 ### Now check some of the written out files. 9943 file_names = ['r1rho_prime', 'r1'] 9944 9945 for file_name_i in file_names: 9946 9947 # Make the file name. 9948 file_name = "%s.out" % file_name_i 9949 9950 # Get the file path. 9951 file_path = get_file_path(file_name, result_dir_name + sep + model) 9952 9953 # Test the file exists. 9954 print("Testing file access to: %s"%file_path) 9955 self.assert_(access(file_path, F_OK)) 9956 9957 # Now open, and compare content, line by line. 9958 file_prod = open(file_path) 9959 lines_prod = file_prod.readlines() 9960 file_prod.close() 9961 9962 # Loop over the lines. 9963 for i, line in enumerate(lines_prod): 9964 # Make the string test 9965 line_split = line.split() 9966 9967 # Continue for comment lines. 9968 if line_split[0] == "#": 9969 print(line), 9970 continue 9971 9972 # Assign the split of the line. 9973 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9974 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9975 9976 if res_num == '52': 9977 # Assert that the value is not None. 9978 self.assertNotEqual(val, 'None')
9979